|
[root@chy01 tasks]# vim /etc/ansible/nginx_install/install.yml
---
- hosts: chy02
remote_user: root
gather_facts: True
roles:
- common
- install
[root@chy01 tasks]# ansible-playbook /etc/ansible/nginx_install/install.yml
[DEPRECATION WARNING]: The use of 'include' for tasks has been deprecated. Use 'import_tasks' for static inclusions or
'include_tasks' for dynamic inclusions. This feature will be removed in a future release. Deprecation warnings can be disabled by
setting deprecation_warnings=False in ansible.cfg.
[DEPRECATION WARNING]: include is kept for backwards compatibility but usage is discouraged. The module documentation details
page may explain more about this rationale.. This feature will be removed in a future release. Deprecation warnings can be
disabled by setting deprecation_warnings=False in ansible.cfg.
PLAY [chy02] *********************************************************************************************************************
TASK [Gathering Facts] ***********************************************************************************************************
ok: [chy02]
TASK [common : Install initializtion require software] ***************************************************************************
failed: [chy02] (item=[u'zlib-devel', u'pcre-devel']) => {"changed": false, "failed": true, "item": ["zlib-devel", "pcre-devel"], "msg": "No Package matching '['zlib-devel'' found available, installed or updated", "rc": 0, "results": []}
to retry, use: --limit @/etc/ansible/nginx_install/install.retry
PLAY RECAP ***********************************************************************************************************************
chy02 : ok=1 changed=0 unreachable=0 failed=1
在执行的时候会报一个错误,这时初步感觉是因为不支持循环,解决方法需要修改一下main.yml的配置文件
[root@chy01 common]# vi tasks/main.yml
- name: Install initializtion require software
yum: name="pcre-devel,zlib-devel" state=installed
[root@chy01 common]# ansible-playbook /etc/ansible/nginx_install/install.yml
再次启动就正常了
[root@chy02 ~]# ps aux |grep nginx
root 5566 0.0 0.0 45484 1284 ? Ss 03:05 0:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/localnginx/conf/nginx.conf
nobody 5568 0.0 0.2 47972 3920 ? S 03:05 0:00 nginx: worker process
nobody 5569 0.0 0.2 47972 3920 ? S 03:05 0:00 nginx: worker process
root 5683 0.0 0.0 112664 976 pts/0 R+ 03:05 0:00 grep --color=auto nginx
//在客户机测试成功
如上需要注意一个问题:需要释放80端口,还需要保证客户机上没有安装nginx(包括用yum安装的) |
|
|