On Tue, 28 Apr 2020 12:45:14 -0700 (PDT) Suresh Karpurapu <karpurapu.sur...@gmail.com> wrote:
> - name: makeing file backup as vfstab.bkp in /tmp > copy: |- > {% if ansible_os_family == "Solaris" %} > src=/etc/vfstab dest=/tmp/vfstab.bkp remote_src=yes > {%- else %} > src=/etc/fstab dest=/tmp/fstab.bkp remote_src=yes > {%- endif %} > when: > - item.changed == true > - item.stdout != "" > with_items: "{{ mounts.results }}" Try this - name: making file backup as vfstab.bkp in /tmp copy: remote_src: true src: "{{ (ansible_os_family == 'Solaris')| ternary('/etc/vfstab', '/etc/fstab') }}" dest: "{{ (ansible_os_family == 'Solaris')| ternary('/tmp/vfstab.bkp', '/tmp/fstab.bkp') }}" loop: "{{ mounts.results }}" when: - item.changed|bool - item.stdout|length > 0 Why do you use the loop? The same copy shall be repeated when the conditions are met? Wouldn't probably the tests "any" or "all" fit the use-case better? https://docs.ansible.com/ansible/latest/user_guide/playbooks_tests.html#test-if-a-list-contains-a-value For example, copy backup if any result has been changed when: mounts.results|json_query('[].changed') is any HTH, -vlado -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/20200428221813.75cee2db%40gmail.com.
pgpxhTyxuVQpk.pgp
Description: OpenPGP digital signature