RHEL8中ansible的安装

本章主要介绍在RHEL8中如何安装ansible

  • ansible是如何工作的
  • 在RHEL8中安装ansible

1.1 ansible的工作原理

如果管理的服务器很多,如几十台甚至几百台,那么就需要一个自动化管理工具了, ansible就是这样的一种自动化管理工具

ansible是通过ssh连接到被管理主机,然后执行相关操作的,如图

ansible主机通过ssh连接到被管理主机时,需要提前设置密钥登录,使得从ansible主机可以无密码登录到被管理主机

1.2 安装ansible

先使用root以后登录rhel801,在其上配置epel源

[root@rhel801 ~]# yum -y install https://mirrors.aliyun.com/epel/epel-release-latest-8.noarch.rpm
[root@rhel801 ~]# sed -i 's|^#baseurl=https://download.fedoraproject.org/pub|baseurl=https://mirrors.aliyun.com|' /etc/yum.repos.d/epel*
[root@rhel801 ~]# sed -i 's|^metalink|#metalink|' /etc/yum.repos.d/epel*
[root@rhel801 ~]#

在rhel801上安装ansible

(1)挂载镜像

[root@rhel801 ~]# mount /dev/cdrom /mnt/
mount: /mnt: /dev/sr0 already mounted on /mnt.
[root@rhel801 ~]#

(2)配置本地yum源

[root@rhel801 ~]# cat /etc/yum.repos.d/aa.repo 
[aa]
name=aa
baseurl=file:///mnt/AppStream
enabled=1
gpgcheck=0

[bb]
name=bb
baseurl=file:///mnt/BaseOS
enabled=1
gpgcheck=0
[root@rhel801 ~]#

安装开发工具

[root@rhel801 ~]# yum -y install groupinstall 开发工具

RHEL8默认的Python版本为3.6,不符合项目的需求。现在升级到3.9

下载python3.9.5

[root@rhel801 ~]# wget https://www.python.org/ftp/python/3.9.5/Python-3.9.5.tgz
[root@rhel801 ~]# tar zxvf Python-3.9.5.tgz

安装必须的包

[root@rhel801 ~]# dnf -y install gcc zlib* libffi-devel

安装Python

[root@rhel801 Python-3.9.5]# cd Python-3.9.5/
[root@rhel801 Python-3.9.5]#  ./configure --prefix=/usr/local/python3 --enable-optimizations
[root@rhel801 Python-3.9.5]# make
[root@rhel801 Python-3.9.5]# make install

删除原先的Python3和pip3

[root@rhel801 Python-3.9.5]# rm -rf /usr/bin/python3
[root@rhel801 Python-3.9.5]# ln -s /usr/local/python3/bin/python3 /usr/bin/python3
[root@rhel801 Python-3.9.5]# rm -rf /usr/bin/pip3
[root@rhel801 Python-3.9.5]# ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3

查看Python3和Pip是否正确的被安装

[root@rhel801 Python-3.9.5]# python3 --version
Python 3.9.5
[root@rhel801 Python-3.9.5]# pip3 --version
pip 21.1.1 from /usr/local/python3/lib/python3.9/site-packages/pip (python 3.9)
[root@rhel801 Python-3.9.5]#

第二步安装ansible

[root@rhel801 ~]# rpm -ivh ansible-2.9.11-1.el8ae.noarch.rpm

错误:依赖检测失败:
    python3-cryptography 被 ansible-2.9.11-1.el8ae.noarch 需要
    python3-jinja2 被 ansible-2.9.11-1.el8ae.noarch 需要
    sshpass 被 ansible-2.9.11-1.el8ae.noarch 需要

需要解决依赖包问题

前面两个使用本地yum源就可以解决了

sshpass找我来拿

安装以上依赖

[root@rhel801 ~]# yum ‐y install python3‐cryptography
[root@rhel801 ~]# yum ‐y install python3‐jinja2
[root@rhel801 ~]# rpm -ivh sshpass-1.06-3.el8ae.x86_64.rpm

再次安装ansible

[root@rhel801 ~]# rpm -ivh ansible-2.9.11-1.el8ae.noarch.rpm 
Verifying...                          ################################# [100%]
准备中...                          ################################# [100%]
正在升级/安装...
   1:ansible-2.9.11-1.el8ae           ################################# [100%]
[root@rhel801 ~]#

使用命令检查ansible的安装结果

[root@rhel801 ~]# ansible --version
ansible 2.9.11
  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, Sep  9 2021, 07:49:02) [GCC 8.5.0 20210514 (Red Hat 8.5.0-3)]
[root@rhel801 ~]# pip3 --version
pip 21.1.1 from /usr/local/python3/lib/python3.9/site-packages/pip (python 3.9)
[root@rhel801 ~]#

这里安装的ansible的版本是2.9.27

  • 10
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值