自动化运维工具Ansible

环境:

纯净Linux系统,未搭建安装任何环境和程序

操作系统:Centos8

python版本:python3

一、配置yum源

(1)进入/etc/yum.repos.d目录下,将Centos-Base.repo备份

  cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak

(2)本次配置清华大学镜像站里的yum源:https://mirrors.cnnic.cn/help/centos/

  将CentOS-Base.repo内的内容替换掉:

  

# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client.  You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#



[BaseOS]
name=CentOS-$releasever - Base
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/BaseOS/$basearch/os/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=BaseOS&infra=$infra
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial

[AppStream]
name=CentOS-$releasever - AppStream
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/AppStream/$basearch/os/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=AppStream&infra=$infra
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial

[PowerTools]
name=CentOS-$releasever - PowerTools
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/PowerTools/$basearch/os/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=PowerTools&infra=$infra
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial


#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/extras/$basearch/os/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial



#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/centosplus/$basearch/os/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial

(3)清除缓存

yum clean all
yum makecache

二、安装ansible

(1)第一步配置epel:

  

yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
或者
yum install epel-release

(2)安装ansible

yum install -y ansible

三、ansible简单介绍

(1)配置文件:

  ansible的配置文件在/etc/ansible目录下:(分别是ansible.cfg、hosts、roles)

  

[root@localhost ansible]# ll
总用量 24
-rw-r--r--. 1 root root 19985 2月 14 06:44 ansible.cfg
-rw-r--r--. 1 root root 1016 2月 14 06:44 hosts
drwxr-xr-x. 2 root root 6 2月 14 06:44 roles

原文地址:https://www.cnblogs.com/oyaisusu/p/12757730.html