ansible 学习5

主机清单配置用户密码,就不需要-k 手动输入密码

[root@localhost ~]# cat /etc/ansible/hosts
[webservers]
192.168.10.127 http_port=80 ansible_ssh_user=root ansible_ssh_pass='123456'
192.168.10.128 http_port=8080

[root@localhost ~]# ansible webservers -e hello=123456 -m shell -a "pwd"
192.168.10.128 | CHANGED | rc=0 >>
/root
192.168.10.127 | CHANGED | rc=0 >>
/home/zxk

ansible配置密钥对:

先生成当前主机的公钥:

 然后可以直接免密登陆:

[root@localhost ~]# ssh root@192.168.10.127
Last login: Wed Jul 14 10:37:16 2021 from 192.168.10.128

 不需要-k参数,直接通过密钥对能登陆远程主机。

 

posted @ 2021-07-14 11:30  beawh  阅读(27)  评论(0编辑  收藏  举报