1

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

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

Thanks Suvorov. It did exactly i wanted. Thanks a ton.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.