Ansible---第一天

一、构建学习环境:

student用户在控制节点(workstation)上安装并配置 Ansible, 要求如下 :

1、安装所需的软件包
[student@workstation ~]$ sudo yum install ansible
2、创建静态inventory文件/home/student/ansible/inventory,要求如下:

	servera属于dev主机组

	serverb属于test和balancers主机组

	serverc和serverd属于prod主机组

	prod主机组属于webservers主机组
[student@workstation ~]$ vim /home/student/ansible/inventory
[dev]
servera
[test]
serverb
[balancers]
serverb
[prod]
serverc
serverd
[webserver:children]
prod
[all:vars]
ansible_user=root
ansible_password=redhat
3、创建ansible配置文件/home/student/ansible/ansible.cfg,要求如下:
	使用/home/student/ansible/inventory清单文件
	角色存放在/home/student/ansible/roles/ 目录
[student@workstation ~]$ cp /etc/ansible/ansible.cfg /home/student/ansible/
inventory      = /home/student/ansible/inventory
roles_path    = /home/student/ansible/roles/
[privilege_escalation]
become=True
become_method=sudo
become_user=root
become_ask_pass=False
[paramiko_connection]

创建roles路径
[student@workstation ~]$ mkdir /home/student/ansible/roles

验证清单文件

[student@workstation ~]$ cd ansible/
[student@workstation ansible]$ ansible-inventory --graph
@all:
  |--@balancers:
  |  |--serverb
  |--@dev:
  |  |--servera
  |--@test:
  |  |--serverb
  |--@ungrouped:
  |--@webserver:
  |  |--@prod:
  |  |  |--serverc
  |  |  |--serverd

在这里插入图片描述

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

	仓库1 :

	Name: RH294_Base

	Description: RH294 base software

	Base url: 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

	启用此软件仓库

编写脚本

[student@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'

增加执行权限,运行脚本验证:
[student@workstation ansible]$ chmod +x adhoc.sh
[student@workstation ansible]$ ./adhoc.sh

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值