2 创建和运行 Ansible 临时命令
题目:
作为系统管理员,您需要在受管节点上安装软件。
照正文所述,创建一个名为 /home/student/ansible/adhoc.sh 的 shell 脚本,该脚本将使用Ansible 临时命令在各个受管节点上安装 yum 存储库:
储存库 1:
- 存储库的名称为 EX294_BASE
- 描述为 EX294 base software
- 基础 URL 为 http://content.example.com/rhel8.0/x86_64/dvd/BaseOS
- GPG 签名检查为:启用状态
- GPG 密钥 URL 为 http://content.example.com/rhel8.0/x86_64/dvd/RPM-GPG-KEY-redhat-release
- 存储库状态为:启用状态
存储库 2:
- 存储库的名称为 EX294_STREAM
- 描述为 EX294 stream software
- 基础 URL 为 http://content.example.com/rhel8.0/x86_64/dvd/AppStream
- GPG 签名检查为:启用状态
- GPG 密钥 URL 为 http://content.example.com/rhel8.0/x86_64/dvd/RPM-GPG-KEY-redhat-release
- 存储库状态为:启用状态
2. 解题思路
- 编辑/home/student/ansible/adhoc.sh
- 使用yum_repository模块
- 使用ansible-doc yum_repository获取到模块使用方法
- 使用shell文件实现
3. 解题
3.1 配置/home/student/ansible/adhoc.sh
vi /home/student/ansible/adhoc.sh
#!/bin/bash
ansible all -m yum_repository -a 'name="EX294_BASE" \
description="EX294 base software" \
baseurl="http://content.example.com/rhel8.0/x86_64/dvd/BaseOS" \
gpgcheck=yes \
gpgkey="http://content.example.com/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.example.com/rhel8.0/x86_64/dvd/AppStream" \
gpgcheck=yes \
gpgkey="http://content.example.com/rhel8.0/x86_64/dvd/RPM-GPG-KEY-redhat-release" \
enabled=yes
'
3.2 给/home/student/ansible/adhoc.sh 加执行权限
chmod +x /home/student/ansible/adhoc.sh
3.3 执行/home/student/ansible/adhoc.sh 脚本
/home/student/ansible/adhoc.sh
4. 确认本题是否成功
没有报错即为正常.
还可以使用以下命令确认
ansible all -a 'yum repolist'