Ansible "When" statement

0 votes

Hello,

With win_stat i can check if a path exists and then set a condition after

       win_stat:
              path: <some path>
       register: A

       win_robocopy:
             src: <>
             dest: <>
              flags: <>
        when: A.stat.exist

My question is, how to achieve this with win find?

       win_find:
             path: <>
         register: A

         debug:
             msg= all files are found
         when: (?)

Any help would be appreciated

Jun 7 in Ansible by Omar
• 140 points

recategorized Jun 7 by Kalgi 169 views
So basically you want to print "all finds are found" when all files are found in the path mentioned?

1 answer to this question.

0 votes

You can try the following workaround. So basically you're getting the number of files in the directory and printing if that number is non zero. I'm not sure if it'll work.

- name: Recursively find /tmp files
    win_find:
           paths: /tmp
           recurse: yes
      register: A.examined

  debug:
      msg = All files found
  when: register > 0
answered Jul 4 by Anvit

Related Questions In Ansible

0 votes
1 answer

When conditional not working in Ansible

Your identation is wrong and when is ...READ MORE

answered Apr 27, 2018 in Ansible by ajs3033
• 7,280 points
935 views
0 votes
1 answer

Running ansible command on a single server when it is deployed to multiple servers

You can try the run_once attribute: Example from ...READ MORE

answered Jun 13, 2018 in Ansible by DareDev
• 6,810 points
230 views
0 votes
1 answer

Permission denied when running ansible playbook through jenkins

Jenkins uses it's own user to execute ...READ MORE

answered Jun 25, 2018 in Ansible by DareDev
• 6,810 points
780 views
0 votes
1 answer

stopping different hosts from reading the same value when usign ansible in loop

Try using this. Create a new directory ...READ MORE

answered Jul 27, 2018 in Ansible by DareDev
• 6,810 points
44 views
+13 votes
2 answers

Git management technique when there are multiple customers and need multiple customization?

Consider this - In 'extended' Git-Flow, (Git-Multi-Flow, ...READ MORE

answered Mar 26, 2018 in DevOps & Agile by DragonLord999
• 8,380 points
245 views
0 votes
1 answer
0 votes
1 answer

Pass sudo password while executing Ansible playbook

Hey @Bob, try something like this: ansible-playbook playbook.yml ...READ MORE

answered Jul 22 in Ansible by Akash
124 views