RHCE-ansible第二次实验,通过ansible远程yum安装

目录

一、实验内容

二、配置过程

1、查看配置文件优先级

2、不改变/etc/ansible/ansible.cfg,重新创建一个配置文件

3、在主机列表配置文件下写入主机

4、查看能否访问成功

5、 查看servera的/etc/yum.repos.d/下有无yum源

6、配置yum源

7、在servera上查看yum源

三、装包测试


一、实验内容

配置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 签名

二、配置过程

1、查看配置文件优先级

[root@workstation ~]# ansible --version

ansible [core 2.12.7]

  config file = /etc/ansible/ansible.cfg

2、不改变/etc/ansible/ansible.cfg,重新创建一个配置文件

[root@workstation ~]# vim ansible.cfg
 
[defaults]
inventory=~/inventory

3、在主机列表配置文件下写入主机
 

[root@workstation ~]# vim inventory
 
servera
serverb
serverc
serverd

4、查看能否访问成功

[root@workstation ~]# ansible servera --list-hosts
  hosts (1):
    servera

5、 查看servera的/etc/yum.repos.d/下有无yum源

[root@servera ~]# cd /etc/yum.repos.d/
[root@servera yum.repos.d]# ll
total 8
-rw-r--r--. 1 root root 358 Apr  4  2019 redhat.repo
-rw-r--r--. 1 root root 365 May 22  2019 rhel_dvd.repo
[root@servera yum.repos.d]# mv rhel_dvd.repo{,.bak}
[root@servera yum.repos.d]# ll
total 8
-rw-r--r--. 1 root root 358 Apr  4  2019 redhat.repo
-rw-r--r--. 1 root root 365 May 22  2019 rhel_dvd.repo.bak

6、配置yum源

[root@workstation ~]# ansible servera -m yum_repository -a 'name=RH294_Stream description="RH294 stream software" baseurl=http://content.example.com/rhel8.0/x86_64/dvd/AppStream gpgcheck=no file=base'
servera | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": true,
    "repo": "RH294_Stream",
    "state": "present"
}

[root@workstation ~]# ansible servera -m yum_repository -a 'name=RH294_Base description="RH294 base software" baseurl=http://content.example.com/rhel8.0/x86_64/dvd/BaseOS gpgcheck=no file=base'
servera | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": true,
    "repo": "RH294_Base",
    "state": "present"
}

7、在servera上查看yum源

[root@servera ~]# cd /etc/yum.repos.d/
[root@servera yum.repos.d]# cat base.repo 
[RH294_Stream]
baseurl = http://content.example.com/rhel8.0/x86_64/dvd/AppStream
gpgcheck = 0
name = RH294 stream software

[RH294_Base]
baseurl = http://content.example.com/rhel8.0/x86_64/dvd/BaseOS
gpgcheck = 0
name = RH294 base software

三、装包测试

[root@servera ~]# yum install httpd -y
Repository RH294_Stream is listed more than once in the configuration
RH294 stream software                   32 MB/s | 5.3 MB     00:00    
RH294 base software                     43 MB/s | 2.2 MB     00:00    
Last metadata expiration check: 0:00:01 ago on Fri 09 Sep 2022 08:53:55 PM CST.
Dependencies resolved.
=======================================================================
 Package            Arch   Version                  Repository    Size
=======================================================================
Installing:
 httpd              x86_64 2.4.37-10.module+el8+2764+7127e69e
                                                    RH294_Stream 1.4 M
Installing dependencies:
 apr                x86_64 1.6.3-9.el8              RH294_Stream 125 k
 apr-util           x86_64 1.6.1-6.el8              RH294_Stream 105 k
 httpd-filesystem   noarch 2.4.37-10.module+el8+2764+7127e69e
                                                    RH294_Stream  34 k
 httpd-tools        x86_64 2.4.37-10.module+el8+2764+7127e69e
                                                    RH294_Stream 101 k
 mod_http2          x86_64 1.11.3-1.module+el8+2443+605475b7
                                                    RH294_Stream 156 k
 redhat-logos-httpd noarch 80.7-1.el8               RH294_Base    25 k
Installing weak dependencies:
 apr-util-bdb       x86_64 1.6.1-6.el8              RH294_Stream  25 k
 apr-util-openssl   x86_64 1.6.1-6.el8              RH294_Stream  27 k
Enabling module streams:
 httpd                     2.4                                                                         
Complete!


[root@servera ~]# rpm -qa | grep httpd
httpd-tools-2.4.37-10.module+el8+2764+7127e69e.x86_64
httpd-2.4.37-10.module+el8+2764+7127e69e.x86_64
redhat-logos-httpd-80.7-1.el8.noarch
httpd-filesystem-2.4.37-10.module+el8+2764+7127e69e.noarch

至此,实验完美成功-。-!

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值