1、ansible all -m ping報錯,信息如下:
[WARNING]: log file at /var/log/ansible.log is not writeable and we cannot create it, aborting
192.168.0.200 | UNREACHABLE! => {
"changed": false,
"msg": "Failed to connect to the host via ssh: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).\r\n",
"unreachable": true
}
解決方法:
(1)權限問題造成的,在/etc/ansible/hosts 中配置如下信息
192.168.0.200 ansible_user=root
之前配置的只有192.168.0.200,沒有后面的那個信息,然后造成這樣的錯誤問題
(2)在配置文件ansible.cfg中啟用remote_user = root,則就不用再hosts文件中配置ansible_user=root了
說明:ansible_user=root
使用/usr/bin/ansible-playbook鏈接的默認用戶名,如果不指定,會使用當前登錄的用戶名
2、 "msg": "Aborting, target uses selinux but python bindings (libselinux-python) aren't installed!"
原因分析:托管節點上開啟了SElinux,你需要安裝libselinux-python,這樣才可使用Ansible中與copy/file/template相關的函數.你可以通過Ansible的yum模塊在需要的托管節點上安裝libselinux-python.
解決方法:ansible all -m shell -a "yum -y install libselinux-python"
注意:是在遠程管理的主機上安裝,不是運行ansible的這個主機安裝
[user@localhost ~]$ ansible 192.168.0.107 -m shell -a "rm -rf /tmp/1.txt"
[WARNING]: Consider using file module with state=absent rather than running rm
192.168.0.107 | SUCCESS | rc=0 >>