ansible简介
ansible是新出现的自动化运维工具,基于Python开发,集合了众多运维工具(puppet、chef、func、fabric)的优点,实现了批量系统配置、批量程序部署、批量运行命令等功能。
ansible是基于 paramiko 开发的,并且基于模块化工作,本身没有批量部署的能力。真正具有批量部署的是ansible所运行的模块,ansible只是提供一种框架。ansible不需要在远程主机上安装client/agents,因为它们是基于ssh来和远程主机通讯的。ansible目前已经已经被红帽官方收购,是自动化运维工具中大家认可度最高的,并且上手容易,学习简单。是每位运维工程师必须掌握的技能之一。
环境
红帽的 rhel-baseos-9.1-x86_64-dvd.iso
安装步骤
1.使用root用户登陆
2.切换到如下目录
[root@localhost yum.repos.d]# pwd
/etc/yum.repos.d
3.使用vim工具 创建一个文件,命名为yum.repovim yum.repo
配置挂载点
#在yum.repo文件里写如下:
[baseos]
name=baseos
gpgcheck=0
baseurl=/mnt/BaseOS
[baseos2]
name=baseos2
gpgcheck=0
baseurl=/mnt/AppStream
截图
挂载
[root@localhost yum.repos.d]# mount /dev/sr0 /mnt
mount: /mnt: WARNING: source write-protected, mounted read-only.
创建ansible.repo仓库文件
[ansible]
name=ansible
baseurl=Index of /rhel8/ansible29/ansible-2.9-for-rhel-8-x86_64-rpms
gpgcheck=0
下载
dnf install ansible -y
正在更新 Subscription Management 软件仓库。
无法读取客户身份本系统尚未在权利服务器中注册。可使用 subscription-manager 进行注册。
ansible 2.0 MB/s | 837 kB 00:00
Docker CE Stable - x86_64 4.1 kB/s | 3.5 kB 00:00
Docker CE Stable - x86_64 8.6 kB/s | 19 kB 00:02
MySQL 8.0 Community Server 4.3 kB/s | 2.6 kB 00:00
MySQL 8.0 Community Server 223 kB/s | 628 kB 00:02
MySQL Connectors Community 4.5 kB/s | 2.6 kB 00:00
MySQL Connectors Community 13 kB/s | 14 kB 00:01
MySQL Tools Community 5.5 kB/s | 2.6 kB 00:00
MySQL Tools Community 121 kB/s | 204 kB 00:01
baseos 1.3 MB/s | 2.7 kB 00:00
baseos2 1.9 MB/s | 3.2 kB 00:00
baseos 2.7 MB/s | 2.7 kB 00:00
baseos2 3.1 MB/s | 3.2 kB 00:00
依赖关系解决。
=============================================================================================
软件包 架构 版本 仓库 大小
=============================================================================================
安装:
ansible-core x86_64 2.13.3-1.el9 repo2 2.7 M
安装依赖关系:
git-core x86_64 2.31.1-2.el9.2 repo2 3.6 M
python3-cffi x86_64 1.14.5-5.el9 repo2 257 k
python3-cryptography x86_64 36.0.1-2.el9 repo2 1.2 M
python3-packaging noarch 20.9-5.el9 repo2 81 k
python3-ply noarch 3.11-14.el9 repo2 111 k
python3-pycparser noarch 2.20-6.el9 repo2 139 k
python3-pyparsing noarch 2.4.7-9.el9 repo 154 k
python3-resolvelib noarch 0.5.4-5.el9 repo2 38 k
sshpass x86_64 1.09-4.el9 repo2 30 k事务概要
=============================================================================================
安装 10 软件包总计:8.3 M
安装大小:35 M
下载软件包:
运行事务检查
事务检查成功。
运行事务测试
事务测试成功。
运行事务
准备中 : 1/1
安装 : sshpass-1.09-4.el9.x86_64 1/10
安装 : python3-resolvelib-0.5.4-5.el9.noarch 2/10
安装 : python3-ply-3.11-14.el9.noarch 3/10
安装 : python3-pycparser-2.20-6.el9.noarch 4/10
安装 : python3-cffi-1.14.5-5.el9.x86_64 5/10
安装 : python3-cryptography-36.0.1-2.el9.x86_64 6/10
安装 : git-core-2.31.1-2.el9.2.x86_64 7/10
安装 : python3-pyparsing-2.4.7-9.el9.noarch 8/10
安装 : python3-packaging-20.9-5.el9.noarch 9/10
安装 : ansible-core-2.13.3-1.el9.x86_64 10/10
运行脚本: ansible-core-2.13.3-1.el9.x86_64 10/10
验证 : python3-pyparsing-2.4.7-9.el9.noarch 1/10
验证 : ansible-core-2.13.3-1.el9.x86_64 2/10
验证 : git-core-2.31.1-2.el9.2.x86_64 3/10
验证 : python3-cffi-1.14.5-5.el9.x86_64 4/10
验证 : python3-cryptography-36.0.1-2.el9.x86_64 5/10
验证 : python3-packaging-20.9-5.el9.noarch 6/10
验证 : python3-ply-3.11-14.el9.noarch 7/10
验证 : python3-pycparser-2.20-6.el9.noarch 8/10
验证 : python3-resolvelib-0.5.4-5.el9.noarch 9/10
验证 : sshpass-1.09-4.el9.x86_64 10/10
已更新安装的产品。已安装:
ansible-core-2.13.3-1.el9.x86_64 git-core-2.31.1-2.el9.2.x86_64
python3-cffi-1.14.5-5.el9.x86_64 python3-cryptography-36.0.1-2.el9.x86_64
python3-packaging-20.9-5.el9.noarch python3-ply-3.11-14.el9.noarch
python3-pycparser-2.20-6.el9.noarch python3-pyparsing-2.4.7-9.el9.noarch
python3-resolvelib-0.5.4-5.el9.noarch sshpass-1.09-4.el9.x86_64完毕!
检查版本
[root@localhost yum.repos.d]# ansible --version
ansible [core 2.13.3]
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.9/site-packages/ansible
ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/bin/ansible
python version = 3.9.14 (main, Sep 21 2022, 00:00:00) [GCC 11.3.1 20220421 (Red Hat 11.3.1-2)]
jinja version = 3.1.2
libyaml = True
[root@localhost yum.repos.d]#