Centos7 使用ansible_ssh_pass
不做免密将密码写在hosts中
安装gcc等依赖 以便安装sshpass
yum –y install gcc
安装sshpass
tar zxvf sshpass-1.06.tar.gz
cd sshpass-1.06/
./configure
make && make install
安装ansible
yum –y install ansible
修改/etc/ansible/ ansible.cfg
在ansible.cfg配置文件中,也会找到如下部分:
- # uncomment this to disable SSH key host checking
- host_key_checking = False
默认host_key_checking部分是注释的,通过找开该行的注释,同样也可以实现跳过 ssh 首次连接提示验证部分。
我的ansible.cfg如下
[defaults] inventory = /etc/ansible/inventory/ #需要手动创建 log_path = /var/log/ansible.log [inventory] [privilege_escalation] [paramiko_connection] [ssh_connection] host_key_checking = False [persistent_connection] [accelerate] [selinux] [colors] [diff] |
再inventory下创建test 并输入以下内容测试ansible_ssh_pass
[test]
10.6.12.109 ansible_ssh_pass='hengtian@123'
10.6.12.102 ansible_ssh_host=10.6.12.102 ansible_ssh_pass="hengtian@123"