ansible搭建
1、准备两台虚拟机
一台IP为192.168.1.129
一台IP为192.168.1.252
2、安装epel
[root@localhost ~]# yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
3、下载安装python-jinja2-2.7.2-4.el7
包链接:https://pan.baidu.com/s/1GaaXp4rgvHA5x6OXsHJ7Kg
提取码:0vdm
复制这段内容后打开百度网盘手机App,操作更方便哦
[root@localhost src]# yum install python-jinja2-2.7.2-4.el7.noarch.rpm
[root@localhost src]# yum install -y python //安装
[root@localhost src]#yum install -y ansible //安装ansible
4、编辑配置文件
[root@localhost src]# cd /etc/ansible/
[root@localhost ansible]# vim hosts //在末尾行添加组
添加内容如下:
[group]
192.168.1.252 ansible_ssh_user=root ansible_ssh_pass=123
[root@localhost ~]# vim /etc/ansible/ansible.cfg //注释掉这两行(去掉#)
验证与使用
[root@localhost ansible]# ansible group -a 'uptime' //group为配置文件中添加的组名
[root@localhost ansible]# ansible -m ping "group"
在192.168.1.129下创建文档3和4
[root@localhost /]# ansible group -m command -a "touch /3"
[root@localhost /]# ansible group -m command -a "touch /4"
切换192.168.1.252的/目录下查看
[root@localhost ~]#cd /
[root@localhost /]#ls
验证完成!