Ansible服务

1、准备ansible 环境
前提是要创建好管理机和被管理机地ssh密钥认证,如果禁止root远程登陆地话,要给普通用户sudo权限。
1)管理机
yum install -y ansible
2)被管理机
yum libselinux-phython -y

2、修改/etc/ansible/ansible.cfg配置文件(ansible配置文件自动生效)
sudo sed -i.bak 's@#remote_port.*22@remote_port = 52113@g' /etc/ansible/ansible.cfg
查看 grep remote_port /etc/ansible/ansible.cfg

3、修改/etc/ansible/hosts
cat >/etc/ansible/hosts<< EOF(指定zhenghao这个组都包含哪些主机)
[zhenghao]
172.16.1.41
172.16.1.7
EOF

4、测试
ansible zhenghao -m command -a "hostname"

猜你喜欢

转载自blog.51cto.com/13670729/2118790