创建一个 shell 脚本名为 adhoc.sh 用以运行 ad-hoc 命令 . 为每个受控节点配罝 yum仓库. 要求如下:
仓库1 :
Name: RH294_Base
Description: RH294 base software
Base urt: file:///mnt/BaseOS
不需要验证钦件包 GPG 签名 启用此软件仓库
仓库 2:
Name: RH294_Stream
Description : RH294 stream software
Base url:file:///mnt/AppStream
不需要验证软件包 GPG 签名
yum_repository
blockinfile
lineinfile
copy
启用此软件仓库
第一步先完成文字转述,再写脚本
配置
[devops@workstation ansible]$ ansible dev -m yum_repository \
> -a 'name="RH294_Base" \
> description="RH294 base software" \
> baseurl=http://content.example.com/rhel8.0/x86_64/dvd/BaseOS \
> gpgcheck=yes \
> gpgkey=/etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release \
> enabled=yes'
servera | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"changed": true,
"repo": "RH294_Base",
"state": "present"
}
配完进行验证;
[devops@workstation ansible]$ ansible dev -a 'ls /etc/yum.repos.d'
servera | CHANGED | rc=0 >>
redhat.repo
RH294_Base.repo
rhel_dvd.repo
验证成功后写脚本;
[devops@workstation ansible]$ vim adhoc.sh
#!/bin/bash
ansible all -m yum_repository \
-a 'name="RH294_Base" \
description="RH294 base software" \
baseurl=http://content.example.com/rhel8.0/x86_64/dvd/BaseOS \
gpgcheck=yes \
gpgkey=/etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release \
enabled=yes'
ansible all -m yum_repository \
-a 'name="RH294_Stream" \
description="RH294 stream software" \
baseurl= http://content.example.com/rhel8.0/x86_64/dvd/AppStream \
gpgcheck=yes \
gpgkey=/etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release \
enabled=yes'
脚本需要增加执行权限
[devops@workstation ansible]$ chmod +x adhoc.sh
运行脚本 ./adhoc.sh
验证;
[devops@workstation ansible]$ ansible all -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 'command_warnings=False' in ansible.cfg to get rid of this message.
servera | CHANGED | rc=0 >>
repo id repo name status
RH294_Base RH294 base software 1,658
RH294_Stream RH294 stream software 4,672
rhel-8.0-for-x86_64-appstream-rpms Red Hat Enterprise Linux 8.0 AppStream 4,672
rhel-8.0-for-x86_64-baseos-rpms Red Hat Enterprise Linux 8.0 BaseOS (d 1,658RH294 base software 345 kB/s | 2.2 MB 00:06
RH294 stream software 2.1 MB/s | 5.3 MB 00:02
Red Hat Enterprise Linux 8.0 AppStream (dvd) 508 kB/s | 3.2 kB 00:00
Red Hat Enterprise Linux 8.0 BaseOS (dvd) 416 kB/s | 2.7 kB 00:00