6-ansible使用问题记录
1.I get a strange error with Ansible. First of all, the first role works fine but when Ansible tries to execute the seconde one it failed because of ssh error.
解决方法:增加async和poll参数
https://stackoverflow.com/questions/43234911/ansible-ssh-error-during-play
2.script模块不支持异步,如果需要使用的话,可以使用copy + command 代替实现
Due to script not requiring python on the remote side, it has no support for async, since the async functionality runs more like a module. I would recommend using copy to copy the script up, and then command to execute the script with async. If you have further questions please stop by IRC or the mailing list: IRC: #ansible on irc.freenode.net mailing list: https://groups.google.com/forum/#!forum/ansible-project
3.ansible使用script如果脚本执行后没有任何返回内容,则如下
[@localhost:yunwei]$ ansible -i /Users/xxxx/ansible-inventory centos7 -m script -a 'hosts_summary.sh' 192.168.56.102 | FAILED! => { "changed": true, "msg": "non-zero return code", "rc": 1, "stderr": "Shared connection to 192.168.56.102 closed.\r\n", "stderr_lines": [ "Shared connection to 192.168.56.102 closed." 这个可以忽略 ], "stdout": "", "stdout_lines": [] } [@localhost:yunwei]$
如下两种情况也会返回rc:1
[@localhost:yunwei]$ ansible -i /Users/xxxx/ansible-inventory centos7 -m shell -a 'grep 11111111 /etc/passwd | wc -l' 192.168.56.102 | CHANGED | rc=0 >> 0 [@localhost:yunwei]$ ansible -i /Users/xxxx/ansible-inventory centos7 -m shell -a 'grep 11111111 /etc/passwd -c' 192.168.56.102 | FAILED | rc=1 >> 0non-zero return code [@localhost:yunwei]$ [@localhost:yunwei]$ ansible -i /Users/xxxx/ansible-inventory centos7 -m shell -a 'grep 11111111 /etc/passwd ' 192.168.56.102 | FAILED | rc=1 >> non-zero return code [@localhost:yunwei]$
如下
[root@localhost ~]# ansible 192.168.169.30 -m raw -a 'grep mysql /etc/group' 192.168.169.30 | FAILED | rc=1 >> Shared connection to 192.168.169.30 closed. non-zero return code //表示已经删除
4.ansible ad-doc执行命令输出json形式,在ansible.cfg中添加如下配置
stdout_callback = json bin_ansible_callbacks = True
5.ansible使用yum安装包,报如下错误
failed: [localhost] (item=[u'centos-release-scl']) => {"ansible_loop_var": "item", "changed": false, "item": ["centos-release-scl"], "msg": "The Python 2 bindings for rpm are needed for this module. If you require Python 3 support use the `dnf` Ansible module instead.. The Python 2 yum module is needed for this module. If you require Python 3 support use the `dnf` Ansible module instead."}
解决方法
#在group_vars/all中加入以下配置ansible_python_interpreter: '/usr/bin/python2.6'
做有积累的事~~

浙公网安备 33010602011771号