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, 2019 in Ansible by Omar
• 140 points

recategorized Jun 7, 2019 by Kalgi 999 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, 2019 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,300 points
5,594 views
+1 vote
2 answers

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 14, 2018 in Ansible by DareDev
• 6,890 points
2,466 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,890 points
4,134 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,890 points
703 views
+15 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 27, 2018 in DevOps & Agile by DragonLord999
• 8,450 points
4,039 views
+2 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, 2019 in Ansible by Akash
5,354 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP