RHCE之路--01安装和配置 Ansible

166 阅读1分钟

本文已参与「新人创作礼」活动,一起开启掘金创作之路

2 创建和运行 Ansible 临时命令

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

  1. 存储库的名称为 EX294_BASE
  2. 描述为 EX294 base software
  3. 基础 URL 为 content.example.com/rhel8.0/x86…
  4. GPG 签名检查为:启用状态
  5. GPG 密钥 URL 为 content.example.com/rhel8.0/x86…
  6. 存储库状态为:启用状态

存储库 2:

  1. 存储库的名称为 EX294_STREAM
  2. 描述为 EX294 stream software
  3. 基础 URL 为 content.example.com/rhel8.0/x86…
  4. GPG 签名检查为:启用状态
  5. GPG 密钥 URL 为 content.example.com/rhel8.0/x86…
  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. 确认本题是否成功

没有报错即为正常.

image.png

ansible all -a 'yum repolist'

image.png