在系统上执行以下任务。
目录
按照下方所述,在控制节点 172.25.250.254 上安装和配置 Ansible:
安装所需的软件包
创建名为 /home/greg/ansible/inventory 的静态清单文件,以满足以下要求:
172.25.250.9 是 dev 主机组的成员
172.25.250.10 是 test 主机组的成员
172.25.250.11 和 172.25.250.12 是 prod 主机组的成员
172.25.250.13 是 balancers 主机组的成员
prod 组是 webservers 主机组的成员
创建名为 /home/greg/ansible/ansible.cfg 的配置文件,以满足以下要求:
主机清单文件为 /home/greg/ansible/inventory
playbook 中使用的角色的位置包括 /home/greg/ansible/roles
- [kiosk@foundation0 ~]$ ssh greg@172.25.250.254
- Activate the web console with: systemctl enable --now cockpit.socket
-
- 启动所有的虚拟机:手动:virt-manager 或者 命令:rht-vmctl start all
- #登录root用户装包
- [greg@bastion ~]$ su -
- Password:
- Last login: Fri Mar 31 11:17:37 GMT 2023 from 172.25.250.250 on pts/0
- [root@bastion ~]$ sudo yum install -y ansible
- #返回grep用户
- [root@bastion ~]# exit
- logout
- 检查:
- [greg@bastion ~]$ ansible --version
- ansible 2.8.0
- config file = /etc/ansible/ansible.cfg
- configured module search path = ['/home/greg/.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, Apr 3 2019, 17:26:03) [GCC 8.2.1 20180905 (Red Hat 8.2.1-3)]
- #创建目录并在目录下创建清单文件
- [greg@bastion ~]$ mkdir ansible
- [greg@bastion ~]$ cd ansible
- [greg@bastion ansible]$ cat inventory
- [dev]
- 172.25.250.9
- [test]
- 172.25.250.10
- [prod]
- 172.25.250.11
- 172.25.250.12
- [balancers]
- 172.25.250.13
- [webservers:children]
- prod
- [all:vars]
- ansible_user=root
- ansible_password=redhat # 填写考试环境提供的密码。(粘贴到虚拟机时要删除注释)
- #从ansible中复制配置文件
- [greg@bastion ansible]$ cp /etc/ansible/ansible.cfg ./
- [greg@bastion ansible]$ vim ansible.cfg
- [defaults]
- inventory = /home/greg/ansible/inventory
- roles_path = /home/greg/ansible/roles
- host_key_checking = False #主机是否校验
-
- [greg@bastion ansible]$ mkdir /home/greg/ansible/roles
-
- 测试:
- [greg@bastion ansible]$ ansible-inventory --graph
- @all:
- |--@balancers:
- | |--172.25.250.13
- |--@dev:
- | |--172.25.250.9
- |--@test:
- | |--172.25.250.10
- |--@ungrouped:
- |--@webservers:
- | |--@prod:
- | | |--172.25.250.11
- | | |--172.25.250.12
- #使用ansible ping所有主机,-m:模块 -o:所有主机
-
- [greg@bastion ansible]$ ansible all -m ping -o
- 172.25.250.13 | SUCCESS => {"ansible_facts": {"discovered_interpreter_python": "/usr/libexec/platform-python"},"changed": false,"ping": "pong"}
- 172.25.250.12 | SUCCESS => {"ansible_facts": {"discovered_interpreter_python": "/usr/libexec/platform-python"},"changed": false,"ping": "pong"}
- 172.25.250.11 | SUCCESS => {"ansible_facts": {"discovered_interpreter_python": "/usr/libexec/platform-python"},"changed": false,"ping": "pong"}
- 172.25.250.10 | SUCCESS => {"ansible_facts": {"discovered_interpreter_python": "/usr/libexec/platform-python"},"changed": false,"ping": "pong"}
- 172.25.250.9 | SUCCESS => {"ansible_facts": {"discovered_interpreter_python": "/usr/libexec/platform-python"},"changed": false,"ping": "pong"}
作为系统管理员,您需要在受管节点上安装软件。
请按照正文所述,创建一个名为 /home/greg/ansible/adhoc.sh 的 shell 脚本,该脚本将使用 Ansible 临时命令在各个受管节点上安装 yum 存储库:
存储库1:
存储库的名称为 EX294_BASE
描述为 EX294 base software
基础 URL 为 http://content/rhel8.0/x86_64/dvd/BaseOS
GPG 签名检查为启用状态
GPG 密钥 URL 为 http://content/rhel8.0/x86_64/dvd/RPM-GPG-KEY-redhat-release
存储库为启用状态
存储库2:
存储库的名称为 EX294_STREAM
描述为 EX294 stream software
基础 URL 为 http://content/rhel8.0/x86_64/dvd/AppStream
GPG 签名检查为启用状态
GPG 密钥 URL 为 http://content/rhel8.0/x86_64/dvd/RPM-GPG-KEY-redhat-release
存储库为启用状态
- #配置仓库 :仓库1和仓库2
-
- [greg@bastion ansible]$ cat adhoc.sh
- #!/bin/bash
- ansible all -m yum_repository -a 'name=EX294_BASE description="EX294 base software" \
- baseurl=http://content/rhel8.0/x86_64/dvd/BaseOS \
- gpgcheck=yes \
- gpgkey=http://content/rhel8.0/x86_64/dvd/RPM-GPG-KEY-redhat-release \
- enabled=yes'
- ansible all -m yum_repository -a 'name=EX294_STREAM description="EX294 stream software" \
- baseurl=http://content/rhel8.0/x86_64/dvd/AppStream \
- gpgcheck=yes \
- gpgkey=http://content/rhel8.0/x86_64/dvd/RPM-GPG-KEY-redhat-release \
- enabled=yes'
-
- -m :
- -a : 指定参数
- description: 描述
- gpgcheck=yes : GPG 签名检查为启用状态
- enabled=yes : 存储库为启用状态
-
- [greg@bastion ansible]$ chmod +x /home/greg/ansible/adhoc.sh
- [greg@bastion ansible]$ ./adhoc.sh
-
- 检查:
- #查看机器仓库
- [greg@bastion ansible]$ ansible all -m shell -a 'yum repolist'
- [WARNING]: Consider using the yum module rather than running 'yum'. If you need to use command because yum is insufficient you can add 'warn:
- false' to this command task or set '