Ansible:安装其软件包后无法启动httpd服务

约翰·W

我正在测试剧本

以下剧本可以安装apache并启动服务:

- hosts: apacheweb
  user: ansibleuser
  become: yes
  gather_facts: no
  tasks:
  - name: Install the apache web server
    yum: pkg=httpd state=latest
    notify: Start HTTPD
  handlers:
  - name: Start HTTPD
    systemd: name=httpd state=started enabled=yes

但不是以下内容,因为它确实安装了httpd软件包,但没有启动该服务并启用它。

- hosts: apacheweb
  user: ansibleuser
  become: yes
  gather_facts: no
  tasks:
  - name: Install the apache web server
    yum: pkg=httpd state=latest
    notify: Start HTTPD
  - name: verify that the web service is running
    command: systemctl status httpd
    register: result
  - debug: var=result
  handlers:
  - name: Start HTTPD
    systemd: name=httpd state=started enabled=yes

错误输出:

PLAY [apacheweb] ******************************************************************************************************************

TASK [Install the apache web server] **********************************************************************************************
changed: [host.learn.com]

TASK [verify that the web service is running] *************************************************************************************
fatal: [host.learn.com]: FAILED! => {"changed": true, "cmd": ["systemctl", "status", "httpd"], "delta": "0:00:00.032030", "end": "2020-04-14 17:59:18.295428", "msg": "non-zero return code", "rc": 3, "start": "2020-04-14 17:59:18.263398", "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:httpd(8)\n           man:apachectl(8)\n\nApr 14 14:50:31 host.learn.com systemd[1]: Starting The Apache HTTP Server...\nApr 14 14:50:31 host.learn.com systemd[1]: Started The Apache HTTP Server.\nApr 14 14:53:45 host.learn.com systemd[1]: Stopping The Apache HTTP Server...\nApr 14 14:53:46 host.learn.com systemd[1]: Stopped The Apache HTTP Server.\nApr 14 17:56:51 host.learn.com systemd[1]: Starting The Apache HTTP Server...\nApr 14 17:56:51 host.learn.com systemd[1]: Started The Apache HTTP Server.\nApr 14 17:57:32 host.learn.com systemd[1]: Stopping The Apache HTTP Server...\nApr 14 17:57:33 host.learn.com systemd[1]: Stopped The Apache HTTP Server.", "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)", "", "Apr 14 14:50:31 host.learn.com systemd[1]: Starting The Apache HTTP Server...", "Apr 14 14:50:31 host.learn.com systemd[1]: Started The Apache HTTP Server.", "Apr 14 14:53:45 host.learn.com systemd[1]: Stopping The Apache HTTP Server...", "Apr 14 14:53:46 host.learn.com systemd[1]: Stopped The Apache HTTP Server.", "Apr 14 17:56:51 host.learn.com systemd[1]: Starting The Apache HTTP Server...", "Apr 14 17:56:51 host.learn.com systemd[1]: Started The Apache HTTP Server.", "Apr 14 17:57:32 host.learn.com systemd[1]: Stopping The Apache HTTP Server...", "Apr 14 17:57:33 host.learn.com systemd[1]: Stopped The Apache HTTP Server."]}

RUNNING HANDLER [Start HTTPD] *****************************************************************************************************

PLAY RECAP ************************************************************************************************************************
host.learn.com : ok=1    changed=1    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0

我创建的第二本剧本可能有什么问题?

富兰克林西霍

Start HTTPD由于任务verify that the web service is running失败,启动服务的处理程序未运行

在每个主机上,一次播放中的所有任务完成后,处理程序仅运行一次。

在您的剧本中,有三个任务。尽管处理程序已通过第一个任务通知,但Install the apache web serveransible仅在完成该播放中的所有三个任务后才运行处理程序。

当任务在主机上失败时,先前通知的处理程序将不会在该主机上运行。

第二个任务的失败使处理程序无法在该主机上运行,​​因此该服务未启动。

如果您希望运行处理程序而与任务失败无关,则可以force_handlers: True在游戏中进行设置

阅读更多:处理程序处理程序故障

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章