zl程序教程

您现在的位置是:首页 >  工具

当前栏目

RHCE之路--02创建和运行 Ansible 临时命令

命令 -- 创建 运行 02 之路 临时 Ansible
2023-09-14 09:15:20 时间

2 创建和运行 Ansible 临时命令

题目:
作为系统管理员,您需要在受管节点上安装软件。
照正文所述,创建一个名为 /home/student/ansible/adhoc.sh 的 shell 脚本,该脚本将使用Ansible 临时命令在各个受管节点上安装 yum 存储库:
储存库 1:

  1. 存储库的名称为 EX294_BASE
  2. 描述为 EX294 base software
  3. 基础 URL 为 http://content.example.com/rhel8.0/x86_64/dvd/BaseOS
  4. GPG 签名检查为:启用状态
  5. GPG 密钥 URL 为 http://content.example.com/rhel8.0/x86_64/dvd/RPM-GPG-KEY-redhat-release
  6. 存储库状态为:启用状态

存储库 2:

  1. 存储库的名称为 EX294_STREAM
  2. 描述为 EX294 stream software
  3. 基础 URL 为 http://content.example.com/rhel8.0/x86_64/dvd/AppStream
  4. GPG 签名检查为:启用状态
  5. GPG 密钥 URL 为 http://content.example.com/rhel8.0/x86_64/dvd/RPM-GPG-KEY-redhat-release
  6. 存储库状态为:启用状态

2. 解题思路

  1. 编辑/home/student/ansible/adhoc.sh
  2. 使用yum_repository模块
  3. 使用ansible-doc yum_repository获取到模块使用方法
  4. 使用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'

在这里插入图片描述