我有这个简单的apache角色(在CentOS7中):
角色/阿帕奇/任务/ main.yml
---
- name: Add epel-release repo
yum:
name: epel-release
state: present
- name: Install Apache2
yum:
name: httpd
state: present
- name: Insert Index Page
copy:
src: index.html
dest: /var/www/html/index.html
角色/阿帕奇/处理/ main.yml
---
- name: Start Apache
service: name=httpd state=started
- name: verify that the web service is running
command: systemctl status httpd
register: status_result
- name: debug
debug: var=status_result
with-roles.yml - playbook与'角色相同的水平'目录
---
- name: Install apache2 in CentOS 7
hosts: 1.23.4.56
become: true
roles:
- apache
然后按照以下方式运行剧本:
$ ansible-playbook -u root --private-key ~/.ssh/this_key.ppk with-roles.yml -i "1.23.4.56" -vvvv
这是屏幕上详细输出的尾端部分:
...
...
"mode": "0644",
"owner": "root",
"path": "/var/www/html/index.html",
"size": 11,
"state": "file",
"uid": 0
}
META: ran handlers
META: ran handlers
PLAY RECAP *******************************************************************************************************************
1.23.4.56 : ok=4 changed=0 unreachable=0 failed=0
但是当我登录到1.23.4.56时,机器已安装httpd但已停止(这意味着处理程序没有运行)。我做错了什么?
答案 0 :(得分:1)
处理程序仅在收到通知时执行。
答案 1 :(得分:0)
根据RenéPijl的提示,答案结果显示在https://serverfault.com/questions/617548/always-trigger-handler-execution-in-ansible。
具体来说,我不得不将其添加到 roles / apache / tasks / main.yml 的底部
...
...
- name: Apache Starter
command: /bin/true
notify: Start Apache