运行剧本报错:
[DEPRECATION WARNING]: Invoking "yum" only once while using a loop via squash_actions is
deprecated. Instead of using a loop to supply multiple items and specifying `name: "{{ item
}}"`, please use `name: ['epel-release', 'nginx']` and remove the loop. This feature will
be removed in version 2.11. Deprecation warnings can be disabled by setting
deprecation_warnings=False in ansible.cfg.
failed: [192.168.154.130] (item=[u'epel-release', u'nginx']) => {"changed": false, "item": ["epel-release", "nginx"], "msg": "No package matching 'nginx' found available, installed or updated", "rc": 126, "results": ["No package matching 'nginx' found available, installed or updated"]}
to retry, use: --limit @/etc/ansible/nginx_install/roles/site.retry
PLAY RECAP *********************************************************************************
192.168.154.130 : ok=1 changed=0 unreachable=0 failed=1
从报错的提示信息看出,就 只运行到tasks的nginx的安装就出错了,估摸着是yum仓库的问题,因为想到之前yum安装也是报了类似的错(https://blog.csdn.net/zhou_438/article/details/89554438),于是对被控制的主机执行:
sudo yum install epel-release
yum update
在ansible的机器上继续试一下剧本文件
果然成功啦
changed: [192.168.154.130] => (item=[u'epel-release', u'nginx'])
TASK [nginx : copy index.html] *************************************************************
changed: [192.168.154.130]
TASK [nginx : copy nginx.conf template] ****************************************************
changed: [192.168.154.130]
TASK [nginx : make sure nginx service running] *********************************************
changed: [192.168.154.130]
RUNNING HANDLER [nginx : restart nginx] ****************************************************
changed: [192.168.154.130]
PLAY RECAP *********************************************************************************
192.168.154.130 : ok=6 changed=5 unreachable=0 failed=0