创建和运行 Ansible 临时命令

作为系统管理员, 您需要在受管节点上安装软件.
请按照下方所述, 创建一个名为/home/student/ansible/adhoc.sh 的 shell 脚本,
该脚本将使用Ansible 临时命令在各个受管节点上安装 yum 存储库:
说白了就是用ansible命令配置yum源


任务要求
存储库 1: 存储库的名称为 rh294_BASE
               描述为 rh294 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: 存储库的名称为 rh294_STREAM
                描述为 rh294 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
注意:
准备工作
因为虚拟机自带 yum 源, 需要先删除, 考试时不需要操作 (可选)

[root@workstation ~]# for i in server{a..d} bastion
> do
> ssh root@$i "rm -rf /etc/yum.repos.d/*"
> done
[root@workstation ~]# su - student
[student@workstation ~]$ cd ansible/

正式开始:
 

[student@workstation ansible]$ vim adhoc.sh 
ansible all -m yum_repository -a "name=rh294_BASE description='rh294 base software' file=rhel_dvd 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=rh294_STREAM description='rh294 stream software' file=rhel_dvd 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
[student@workstation ansible]$ chmod +x adhoc.sh
[student@workstation ansible]$ ./adhoc.sh 

考察的知识点

Ansible的yum_repository 模块

  • ansible-doc yum_repository
  • 利用yum_repository 模块可以对受控主机进行yum源配置
    创建仓库
  • - name: Add repository
      yum_repository:
        name: epel
        description: EPEL YUM repo
        baseurl: https://download.fedoraproject.org/pub/epel/$releasever/$basearch/
    
    - name: Add multiple repositories into the same file (1/2)
      yum_repository:
        name: epel
        description: EPEL YUM repo
        file: external_repos
        baseurl: https://download.fedoraproject.org/pub/epel/$releasever/$basearch/
        gpgcheck: no
    
    - name: Add multiple repositories into the same file (2/2)
      yum_repository:
        name: rpmforge
        description: RPMforge YUM repo
        file: external_repos
        baseurl: http://apt.sw.be/redhat/el7/en/$basearch/rpmforge
        mirrorlist: http://mirrorlist.repoforge.org/el7/mirrors-rpmforge
        enabled: no
    

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

晚睡晚起秦叁叁

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值