Ansible是一款自动化运维工具,基于Python开发,集合了众多运维工具(puppet、cfengine、chef、func、fabric)的优点,实现了批量系统配置、批量程序部署、批量运行命令等功能。
Ansible是基于模块工作的,本身没有批量部署的能力。真正具有批量部署的是Ansible所运行的模块,Ansible只是提供一种框架。主要包括:
ansible构架图:
配置yum epel源
[root@localhost ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-8.repo
[root@localhost ~]# sed -i -e ‘/mirrors.cloud.aliyuncs.com/d‘ -e ‘/mirrors.aliyuncs.com/d‘ /etc/yum.repos.d/CentOS-Base.repo
[root@localhost ~]# rpm --reinstall https://mirrors.aliyun.com/epel/epel-release-latest-8.noarch.rpm
ed -i ‘s|$releasever|8|g‘ /etc/yum.repos.d/*warning: /var/tmp/rpm-tmp.HuADTa: Header V4 RSA/SHA256 Signature, key ID 2f86d6a1: NOKEY
[root@localhost ~]# sed -i ‘s|^#baseurl=https://download.fedoraproject.org/pub|baseurl=https://mirrors.aliyun.com|‘ /etc/yum.repos.d/epel*
[root@localhost ~]# sed -i ‘s|^metalink|#metalink|‘ /etc/yum.repos.d/epel*
[root@localhost ~]# sed -i ‘s|$releasever|8|g‘ /etc/yum.repos.d/*
[root@localhost ~]# yum -y install ansible
Installed:
ansible-2.9.16-1.el8.noarch libsodium-1.0.18-2.el8.x86_64 python3-babel-2.5.1-5.el8.noarch
python3-bcrypt-3.1.6-2.el8.1.x86_64 python3-jinja2-2.10.1-2.el8_0.noarch python3-jmespath-0.9.0-11.el8.noarch
python3-markupsafe-0.23-19.el8.x86_64 python3-paramiko-2.4.3-1.el8.noarch python3-pip-9.0.3-18.el8.noarch
python3-pyasn1-0.3.7-6.el8.noarch python3-pynacl-1.3.0-5.el8.x86_64 python3-pytz-2017.2-9.el8.noarch
python3-pyyaml-3.12-12.el8.x86_64 python3-setuptools-39.2.0-6.el8.noarch python36-3.6.8-2.module_el8.3.0+562+e162826a.x86_64
sshpass-1.06-9.el8.x86_64
Complete!
[root@localhost ~]# ansible --version
ansible 2.9.16
config file = /etc/ansible/ansible.cfg
configured module search path = [‘/root/.ansible/plugins/modules‘, ‘/usr/share/ansible/plugins/modules‘]
ansible python module location = /usr/lib/python3.6/site-packages/ansible
executable location = /usr/bin/ansible
python version = 3.6.8 (default, Dec 5 2019, 15:45:45) [GCC 8.3.1 20191121 (Red Hat 8.3.1-5)]
[root@localhost ~]# ansible -m setup localhost|grep ansible_python_version
"ansible_python_version": "3.6.8",
原文:https://www.cnblogs.com/fangxinxin/p/14231761.html