I am using ansible for on of my project in which i want to execute command when the previous command returns me some value. Like I am checking the root folder and if files are found more than lets say 10, execute the next command.
I am trying to do this with ansbile in below manner. Pls help
---
- hosts: debug
user: root
tasks:
- name: check if count ge 15
command: bash -c "ls /root | wc -l"
register: ifcount
ignore_errors: True
- debug: var=ifcount.stdout
- name: create new file if above command sucessfull
command: touch /tmp/file.html
when: ifcount -ge 15
Konstantin Suvorov
68.9k9 gold badges175 silver badges202 bronze badges
asked May 17, 2017 at 8:34
1 Answer 1
when is a Jinja2 expression. It uses Jinja2 comparison operators.
Also note, that you try to compare ifcount, whereas actual value to compare is ifcount.stdout.
Try: when: ifcount.stdout | int >= 15
answered May 17, 2017 at 8:46
Sign up to request clarification or add additional context in comments.
1 Comment
Deven
Thanks Suvorov. It did exactly i wanted. Thanks a ton.