我需要在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
当我执行playbook时,似乎处理程序没有运行,因为输出结果如下:
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,所以是否有什么明显的问题我可能会忽略?
changed_when: true
元素。这将使Ansible始终考虑YUM已经“更改”了某些内容,然后始终通知处理程序触发,无论包是否已安装。 - Stevel