I'm trying to craft a role that will run only if a variable gets registered is of a certain value, in this case, the md5sum of a file.
The role/main.yml looks like this:
----
- name: Has this already been done? Check for the script, & it's md5sum
command: md5sum /usr/sbin/sendmail.postfix
register: md5sum
ignore_errors: True
- name: What's the value of md5sum?
debug: var=md5sum
- include: dontrunthen.yml
when: md5sum.stdout == "e420fc39246a11c890b30b71dda4f976"
- include: dontrunthen.yml
when: md5sum.stdout == "ac0e57862902c2b11c7dfcdca5a79c30"
- include: runme_postfix.yml
when: md5sum.stdout != "e420fc39246a11c890b30b71dda4f976"
That md5sum is defintely that of the file in question:
# md5sum /usr/sbin/sendmail.postfix
e420fc39246a11c890b30b71dda4f976 /usr/sbin/sendmail.postfix
Yet when I run the playbook, it "skips" the steps which should be making the role use the dontrunthen.yml playbook. It then runs the tasks in runme_postfix.yml. dontrunthen.yml should just fail and end the play:
---
- name: We don't need to run if we've made it here...
fail: msg="Looks like this role has already been applied, try checking the file that should have been created
Any idea why this might be happening? It's not the behaviour I would expect. I have other working roles which conditionally run depending on OS, etc.
Also, is there a good reference for terms that can be used with the when statement, like varname.stdout, varname.stderr etc.? There are lots of different mentions and uses in the Ansible docs, but i can't seem to find anywhere that these are documented.
You can use this option, It's being tested and verified.
If all goes well here would be the output -
# ansible-playbook -i ansible_hosts site.yml -u root -v
I hope this will meet your requirement.