1、准备环境
Redhat8.2 |
IP |
运用 |
master |
192.168.8.129 |
ansible运维工具 |
node1 |
192.168.8.132 |
apache(httpd) |
node2 |
192.168.8.133 |
mysql数据库 |
node3 |
192.168.8.134 |
php |
2、ansible安装
//安装网络仓库
[root@master ~]
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 2595 100 2595 0 0 22964 0 --:--:-- --:--:-- --:--:-- 22964
//安装epel源
[root@master ~]
//安装ansible
[root@master ~]
//查看ansible版本
[root@master ~]
ansible 2.9.23
config file = /etc/ansible/ansible.cfg
configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3.6/site-packages/ansible
executable location = /usr/bin/ansible
python version = 3.6.8 (default, Dec 5 2019, 15:45:45) [GCC 8.3.1 20191121 (Red Hat 8.3.1-5)]
[root@master ~]
- 构建 一个清单文件,移动到 /opt/project目录下方便管理
[root@master project]
ansible.cfg inventory
- 将要配置httpd、mysql、php的被控主机的IP添加到ansible主机清单
[root@master project]
[httpd]
192.168.8.132 ansible_user=root ansible_password=1 //用户和密码
[mysql]
192.168.8.133 ansible_user=root ansible_password=1
[php]
192.168.8.134 ansible_user=root ansible_password=1
[root@master project]
[root@master project]
192.168.8.134 | SUCCESS => <