RHCE(2)

创建一个 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    

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值