CE证作业01

本文详细介绍如何在Ansible环境中安装、配置并使用ad-hoc命令,包括创建静态inventory文件、配置ansible.cfg,以及执行yum仓库配置任务。涉及主机组划分和角色管理,通过shell脚本实现自动化部署。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.安装并配置Ansible

在控制节点上安装并配置 Ansible, 要求如下:
​ 安装所需的钦件包
- ​ 创建静态 inventory 文件 /home/devops/ansible/inventory, 要求如下:
- servera 属于dev 主机组
- serverb 属于 test 和 balancers 主机组
- serverc 和 serverd 满于 prod 主机组
- prod 主机组属于 Webserver 主机组

- 创建 ansible配置文件/home/devops/ansible/ansible.cfg , 要求如下 :
- 使用 /home/devaps/ansible/inventory 清单文件
- 角色 role目录存放在 /home/devops/ansibfe/roles


创建ansibles文件

[devops@workstation ~]$ mkdir /home/devops/ansible

进入静态inventory文件中按要求编辑

[devops@workstation ansible]$ vim inventory

 验证

[devops@workstation ansible]$ ansible-inventory -i inventory --graph

 完成后配置清单文件

[devops@workstation ansible]$ vim ansible.cfg

 创建角色目录

[devops@workstation ansible]$ mkdir roles

进入inventory文件中给所有人

[devops@workstation ansible]$ ansible all -m ping

 


2.创建并运行 Ansibie ad-hoc 命令
创建一个 shell 脚本名为 adhoc.sh 用以运行 ad-hoc 命令 . 为每个受控节点配罝 yum仓库. 要求如下:

仓库1 :

- ​ Name: RH294_Base
- ​ Description: RH294 base software
- ​ Base urt: http://content.example.com/rhel8.0/x86_64/dvd/BaseOS
- ​ 需要验证钦件包 GPG 签名
- ​ GPG key 在: /etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
- ​ 启用此软件仓库

仓库 2:

- ​ Name: RH294_Stream
- ​ Description : RH294 stream software
- ​ Base url: http://content.example.com/rhel8.0/x86_64/dvd/AppStream
- ​ 需要验证软件包 GPG 签名
- ​ GPG key 在: /etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
- ​ 启用此软件仓库

先启动机器
rht-vmctl start all
打开参考文件
[devops@workstation ansible]$ ansible-doc yum_repository

在文件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]$ ansible all -a 'yum repolist'

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值