ansible 使用密码而不是免秘钥执行

需求,通过ansible查看k8s集群中的三台机器是否还存活

  • 服务器:
    • 192.168.80.130 k8smaster
    • 192.168.80.131 k8snode2
    • 192.168.80.128 k8snode1

修改/etc/hosts

192.168.80.130 k8smaster
192.168.80.131 k8snode2
192.168.80.128 k8snode1

修改ansible hosts

vim /etc/ansible/hosts
[k8s]
k8smaster ansible_ssh_user=root ansible_ssh_port=22 ansible_ssh_pass=james
k8snode1 ansible_ssh_user=root ansible_ssh_port=22 ansible_ssh_pass=james
k8snode2 ansible_ssh_user=root ansible_ssh_port=22 ansible_ssh_pass=james

修改/etc/ansible/ansible.cfg

sed -i 's/.*\(host_key_checking\)/\1/' /etc/ansible/ansible.cfg
# 去掉配置文件中的注释
#host_key_checking = False
host_key_checking = False

最后结果

# ansible  k8s -m ping 
k8smaster | SUCCESS => {
    "changed": false, 
    "ping": "pong"
}
k8snode2 | SUCCESS => {
    "changed": false, 
    "ping": "pong"
}
k8snode1 | SUCCESS => {
    "changed": false, 
    "ping": "pong"
}


https://www.jianshu.com/p/9e58a598e448

发表评论

电子邮件地址不会被公开。