Ansible 2.1
In the playbook, I started a process:
- name: Start Automation Agent, and enable start on boot
service: name=mongodb-mms-automation-agent state=started enabled=yes
From play recap, it appears the process has successfully started.
TASK [install : Start automation agent, and enable start on boot] **************
changed: [server1]
However, when log in to remote host and do a ps
, the process is not running. Checking on process log it had failed some pre-requisite (intended).
How do I write a task in a playbook to confirm the process has successfully started?
Best Answer
You can check with the
failed
Jinja2 filter after running your command that checks if the process is running.Here is an example that uses the output of the command
systemctl status apache2
to decide if Apache is running:If the command of the first task failed, the second task will fail and show why the first task failed.
The return code is stored in
service_apache_status.rc
.Example output of a failure:
Here is different (albeit possibly less reliable) way, using
pgrep
, to check if the process is running: