1.安装
要先安装epel-release,否则安装ansible报错,如果不是root要sudo。
yum -y install epel-release
yum -y install ansible
2.配置host
编辑此文件,在文件末尾中输入:
vim /etc/ansible/hosts
其中中括号内是你的集群名称,下面是你的机器ip地址。
3.免密登录
输入如下指令,不要疑惑,一直回车就可以
ssh-keygen -t rsa
将秘钥复制到其他机器
ssh-copy-id -i /root/.ssh/id_rsa.pub root@192.168.146.11
ssh-copy-id -i /root/.ssh/id_rsa.pub root@192.168.146.22
4.测试
ansible ansible -m shell -a "echo 'hello world'"
双引号内为你的shell指令,如图既可。
5.问题
首先机器直接是要互ping能通的,如果不能通,或者报错Could not resolve hostname,
vim /etc/hosts
在文件中设置如下,加入所有主机的地址映射即可