ansible - conditional execution of playbook based on exit status of the command module? -


i trying write playbook execute tasks if package installed on hosts.

is possible register output command module , run tasks depending upon exit status of command ?

something this: play tasks

you on right path. if httpd doesnt exist, playbook execution fail. can use ignore_errors continue execution , run subsequent tasks based on return code of httpd_result. have given example below:

-  hosts: localhost    tasks:     - command: "which httpd"       register: httpd_result       ignore_errors: true     - debug: msg="found http"       when: httpd_result.rc == 0     - debug: msg="not found httpd"       when: httpd_result.rc!=0 

here, instead of debug statements, can put whatever conditional tasks need run. hope helps.


Comments