标签:ble key class 分享图片 keygen 自动 attr 记录 root用户
yum install epel-release
yum install ansible
vim /etc/ansible/hosts
这里添加被管理主机的IP,可以是外网IP和内网IP
ssh-keygen -t rsa
一路回车即可在$HOME/.ssh目录下生成id_rsa和id_rsa.put私钥和公钥两个文件。
注: 如果在生成密钥的时候设置了密码,ansible每次执行命令的时候,都会提示输入密钥密码,可通过下面的命令记住密码。
ssh-agent bsh
ssh-add ~/.ssh/id_rsa
ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.0.200
ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.0.201
ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.0.203
注:ssh-copy-id命令会自动将id_rsa.pub文件的内容追加到远程主机root用户下.ssh/authorized_keys文件中。
vim /etc/ansible/ansible.cfg
1> 禁用每次执行ansbile命令检查ssh key host
host_key_checking = False
2> 开启日志记录
log_path = /var/log/ansible.log
3> ansible连接加速配置
[accelerate]
#accelerate_port = 5099
accelerate_port = 10000
#accelerate_timeout = 30
#accelerate_connect_timeout = 5.0
# If set to yes, accelerate_multi_key will allow multiple
# private keys to be uploaded to it, though each user must
# have access to the system via SSH to add a new key. The default
# is "no".
accelerate_multi_key = yes
最后测试下在三台管理机器批量执行一个ping命令
ansible all -m ping
从上图可以看出,在每台管理机器上都成功执行了ping命令。
常用的一些批量执行命令:
ansible all -m command -a ‘pwd‘
标签:ble key class 分享图片 keygen 自动 attr 记录 root用户
原文地址:https://www.cnblogs.com/liuboswu/p/8806725.html