Running webservice run verification from ansible playbook

I am getting the following error when I run the playbook at the end of the Optimizing your playbook lecture:

TASK [verify that the webservice is running] *****************************************************************************************************************************************************************************************

fatal: [localhost]: FAILED! => {"changed": true, "cmd": ["systemctl", "status", "httpd"], "delta": "0:00:00.021929", "end": "2018-09-24 21:00:54.027817", "msg": "non-zero return code", "rc": 3, "start": "2018-09-24 21:00:54.005888

", "stderr": "", "stderr_lines": [], "stdout": "● httpd.service - The Apache HTTP Server\n Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)\n Active: inactive (dead)\n Docs: man:htt

pd(8)\n man:apachectl(8)", "stdout_lines": ["● httpd.service - The Apache HTTP Server", " Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)", " Active: inactive (dead)", "

Docs: man:httpd(8)", " man:apachectl(8)"]}

fatal: [localhost.localdomain]: FAILED! => {"changed": true, "cmd": ["systemctl", "status", "httpd"], "delta": "0:00:00.008248", "end": "2018-09-24 21:00:54.077745", "msg": "non-zero return code", "rc": 3, "start": "2018-09-24 21:

00:54.069497", "stderr": "", "stderr_lines": [], "stdout": "● httpd.service - The Apache HTTP Server\n Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)\n Active: inactive (dead)\n D

ocs: man:httpd(8)\n man:apachectl(8)", "stdout_lines": ["● httpd.service - The Apache HTTP Server", " Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)", " Active: inactive (de

ad)", " Docs: man:httpd(8)", " man:apachectl(8)"]}

to retry, use: --limit @/home/test/playbooks/outline/webserver.retry


Could someone give me an idea of what I may have incorrectly? I did not see any errors in the --check dry run.
  • post-author-pic
    Terrence C
    09-25-2018

    Hi Benjamin,


    Ansible v2.x changed the way that handlers are run inside a playbook. Now, handlers are only called after the successful run of ALL tasks in a playbook. 

    So the solution in this case is to swap the position of starting the service and checking the service in your playbook. Start the service as a task and throw the event to check the service so it runs at the end, and it will resolve this particular issue.

Looking For Team Training?

Learn More