BharathKumarRaju Dasararaju BharathKumarRaju Dasararaju - 1 year ago 147
YAML Question

Error while running simple ansible playbook

playbook is as below...

[ansible@ansible2 outline]$ cat webserver.yaml
--- #Create an YAML from an outline

  • hosts: web
    connection: ssh
    remote_user: ansible
    become: yes
    become_method: sudo
    gather_facts: yes

    test: raju
    - /home/ansible/playbooks/conf/copyright.yaml


    • name: web_domain
      prompt: WEB DOMAIN


    • name: install apache web server
      yum: pkg=httpd state=latest
      notify: start the service

    • name: check service
      command: service httpd status
      register: result

    • debug: var=result


    • name: start the service
      service: name=httpd state=restarted

[ansible@ansible2 outline]$

and the error as below...

[ansible@ansible2 outline]$ ansible-playbook webserver.yaml

PLAY [web] *********************************************************************

TASK [setup] *******************************************************************

ok: []

TASK [install apache web server] ***********************************************

changed: []

TASK [check service] ***********************************************************
fatal: []: FAILED! => {"changed": true, "cmd": ["service", "httpd", "status"], "delta": "0:00:00.039489", "end": "2016-10-30 04:53:51.833760", "failed": true, "rc": 3, "start": "2016-10-30 04:53:51.794271", "stderr": "", "stdout": "httpd is stopped", "stdout_lines": ["httpd is stopped"], "warnings": ["Consider using service module rather than running service"]}

NO MORE HOSTS LEFT *************************************************************

RUNNING HANDLER [start the service] ********************************************
to retry, use: --limit @/home/ansible/outline/webserver.retry

PLAY RECAP ********************************************************************* : ok=2 changed=1 unreachable=0 failed=1

Answer Source

Try check service's status using /etc/init.d

- name: check service
  stat: path=/etc/init.d/httpd
  register: result
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download