gpt4 book ai didi

ansible - 运行简单的 ansible 剧本时出错

转载 作者:行者123 更新时间:2023-12-01 13:40:57 24 4
gpt4 key购买 nike

剧本如下...

[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

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

vars_prompt:
- name: web_domain
prompt: WEB DOMAIN

tasks:
- 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

handlers:
- name: start the service
service: name=httpd state=restarted

[ansible@ansible2 outline]$

错误如下...

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

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

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

ok: [web2.bharathkumarraju.com]

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

changed: [web2.bharathkumarraju.com]

TASK [check service] ***********************************************************
fatal: [web2.bharathkumarraju.com]: 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 *********************************************************************
web2.bharathkumarraju.com : ok=2 changed=1 unreachable=0 failed=1

最佳答案

运行 service httpd status 的退出代码与 0 不同,因为该服务未启动。处理程序总是在剧本的末尾运行,而不是在收到通知时运行。

一种解决方案是在检查服务状态时放置一个“ignore_errors: true”。另一种解决方案是删除处理程序+通知并在 yum 之后放置一个服务模块:

- service: name=httpd status=started enabled=yes

关于ansible - 运行简单的 ansible 剧本时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40326181/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com