When receiving the value of the Service variable in the task "Definition of service", depending on its value, add a path to the task "Detecting the last version of service" according to certain values ​​in the ServiceUp (ServiceUp records the same possible Service values)

vars: Service: "{{ TypeOfService }}" ServiceUP: - { Service: Service.1, ServiceUpSRC: path1 } - { Service: Service.2, ServiceUpSRC: path2 } tasks: - name: Definition of service raw: ls /home/user/ | grep Service register: TypeOfService - debug: msg="{{ TypeOfService.stdout_lines }}" - name: Detecting the last version of service raw: ls -tl /mnt/r/TypeOfService/{{ item.ServiceUpSRC }}/ | grep Linux | awk '{ print $9, $10, $11 }'| head -1 delegate_to: 127.0.0.1 register: version with_items: - "{{ ServiceUP }}" - debug: msg="{{ version.stdout_lines }}" 
  • Your register is different, ServiceUp and ServiceUP are different things - andreymal
  • Fixed an annoying bug with ServiceUP. Given when it runs through a loop as specified in ServiceUP, how can it be redone so that it chooses from the ServiceUP values ​​depending on the TypeOfService result? - FastPuppy

1 answer 1

But in this form it should work exactly, it is only desirable to determine the default path after all.

 tasks: - name: Definition of service raw: ls /home/user/ | grep Service register: TypeOfService - set_fact: ServiceUpSRC: path1 when: TypeOfService == 'Service.1' - set_fact: ServiceUpSRC: path2 when: TypeOfService == 'Service.2' - debug: msg="{{ TypeOfService.stdout_lines }}" - name: Detecting the last version of service raw: ls -tl /mnt/r/TypeOfService/{{ item.ServiceUpSRC }}/ | grep Linux | awk '{ print $9, $10, $11 }'| head -1 delegate_to: 127.0.0.1 register: version with_items: - "{{ ServiceUP }}" - debug: msg="{{ version.stdout_lines }}"