我需要在Centos 6.5中设置Apache / mod_wsgi,所以我的主要YAML文件是这样的:
---
- hosts: dev
tasks:
- name: Updates yum installed packages
yum: name=* state=latest
- hosts: dev
roles:
- { role: apache }
这应该更新所有yum安装的软件包,然后执行apache角色。
apache角色配置为安装Apache / mod_wsgi,将Apache设置为在引导时启动并重新启动它。以下是
roles/apache/tasks/main.yml
的内容:---
- name: Installs httpd and mod_wsgi
yum: name={{ item }} state=latest
with_items:
- httpd
- mod_wsgi
notify:
- enable httpd
- restart httpd
和
roles/apache/handlers/main.yml
中的处理程序:---
- name: enable httpd
service: name=httpd enabled=yes
- name: restart httpd
service: name=httpd state=restarted
处理程序似乎没有运行,因为执行我的剧本时给出了以下输出:
PLAY [dev] ********************************************************************
GATHERING FACTS ***************************************************************
ok: [dev.example.com]
TASK: [Updates yum installed packages] ****************************************
ok: [dev.example.com]
PLAY [dev] ********************************************************************
GATHERING FACTS ***************************************************************
ok: [dev.example.com]
TASK: [apache | Installs httpd and mod_wsgi] **********************************
ok: [dev.example.com] => (item=httpd,mod_wsgi)
PLAY RECAP ********************************************************************
dev.example.com : ok=4 changed=0 unreachable=0 failed=0
当我
vagrant ssh
进入虚拟机时,sudo service httpd status
显示httpd
已停止,而sudo chkconfig --list
显示尚未启用init
启动它。我只是从Ansible开始,所以我可能会遗漏一些明显的东西吗?
最佳答案
好吧,回答我自己的问题时,我意识到我错过了一个微妙的要点:
http://docs.ansible.com/playbooks_intro.html#handlers-running-operations-on-change
具体来说,仅当任务引入更改时才生成通知信号。因此,对于我的用例,我认为我将在独立任务中启用和启动Apache,而不是依赖于更改信号处理程序。
关于ansible-playbook - Ansible角色和处理程序-无法使角色处理程序正常工作,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24732627/