Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #### Running the task without condition shows us the 'stdout' msg
- TASK [qualitybox : Pear | install pear mail module] ****************************
- ok: [wiki.example.com] => {
- "changed": false,
- "invocation": {
- "module_args": {
- "name": "Mail",
- "state": "latest"
- },
- "module_name": "pear"
- },
- "msg": "package(s) already installed"
- }
- TASK [qualitybox : debug] ******************************************************
- task path: /home/greg/src/ansible-digitalocean/roles/qualitybox/tasks/install_pear.yml:71
- ok: [wiki.example.com] => {
- "msg": {
- "changed": false,
- "msg": "package(s) already installed"
- }
- }
- #### So we try to incorporate a 'changed_when' and 'failed_when' condition
- - name: Pear | install pear mail module
- pear: name=Mail state=latest
- register: pear_result
- changed_when: "'already installed' not in pear_result.stdout"
- failed_when: "'already installed' not in pear_result.stdout and pear_result.stderr"
- ###### But we get an error
- fatal: [wiki.example.com]: FAILED! => {
- "failed": true,
- "msg": "The conditional check ''already installed' not in pear_result.stdout' failed. The error was: error while evaluating conditional ('already installed' not in pear_result.stdout): Unable to look up a name or access an attribute in template string ({% if 'already installed' not in pear_result.stdout %} True {% else %} False {% endif %}).\nMake sure your variable name does not contain invalid characters like '-': argument of type 'StrictUndefined' is not iterable"
- }
- ###### SOLVED: The reason this fails is because the ansible extras PEAR module does NOT return 'stdout'. Instead there is the 'msg' attribute which we can test:
- ###### SEE https://github.com/ansible/ansible-modules-extras/blob/devel/packaging/language/pear.py
- changed_when: "'already installed' not in pear_result.msg"
Add Comment
Please, Sign In to add comment