此次測試總共有三台機,分別如下:
ansible服務器:10.0.0.20
client01:10.0.0.21
client02:10.0.0.22
一、安裝ansible
1、 python版本需要2.6以上,不過通過centos7都會默認安裝上python2.7.5,查看方法:python -V
2、 添加yum 源
a、 vim /etc/yum.repos.d/ansible
b、 添加如下內容:
[epel]
name = all source for ansible
baseurl = https://mirrors.aliyun.com/epel/7/x86_64/
enabled = 1
gpgcheck = 0
[ansible]
name = all source for ansible
baseurl = http://mirrors.aliyun.com/centos/7.3.1611/os/x86_64/
enabled = 1
gpgcheck = 0
3、 yum clean all
4、 安裝ansible:yum install ansible -y
二、配置ansible
1、 使用ansible前需實現ansible服務器對另外兩台機的ssh無密碼訪問,操作如下:
a、 輸入命令:ssh-keygen,一直按回車,直至完成操作;
b、 命令:ssh-copy-id root@10.0.0.21 ,然后輸入連接密碼即可實現無密碼訪問,另外一台機的設置方式一樣,不再贅述。
2、 添加ansible客戶機組,命令:vim /etc/ansible/hosts,在最后面添加如下內容:
[group1]
10.0.0.21
10.0.0.22
三、使用ansible
1、 在另外兩台機上執行ping命令:ansible group1 -m ping
2、 復制本機文件到組group1:ansible group1 -m copy -a “src=/etc/hosts dest=/etc/”
3、 幫group1安裝軟件:ansible group1 -m shell -a “yum install wget -y”
PS:此次全部操作都是用root用戶
