#1.安装ansible
apt install ansible -y
#2.配置ansible的hosts
#hosts模板
#[主机群组名称]
#远程主机名(可以和hostname不一样) ansible_host=远程主机ip ansible_user=远程用户
#注意配置了ssh免密登录,就不用ansible_root_password=****,否则需要。
#建议配置。可以看上一篇文章配置ssh免密登录
vim /etc/ansible/hosts
#文件末尾追加
[web] #主机群组
web1 ansible_host=192.168.47.132 ansible_user=root
[db] #主机群组
db1 ansible_host=192.168.47.135 ansible_user=root
#3.测试ansible是否配置成功
#执行命令
ansible all -m ping
#输出如下则配置成功
db1 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python3"
},
"changed": false,
"ping": "pong"
}
web1 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python3"
},
"changed": false,
"ping": "pong"
}
ubuntu20.04配置ansible远程其他服务器
最新推荐文章于 2024-07-19 22:07:59 发布