方法一、通过本地yum源安装
centos 使用默认的yum源安装 ——> ansible-core
rhel yum 源安装 ——> ansible
这里实验用的是2.9的版本
ansible的安装文件 Index of /ansiblehttps://releases.ansible.com/ansible/ ansible依赖与python它是通过python进行开发的
[root@rhce ~]# lsblk //查看是否连接成功
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sr0 11:0 1 9.4G 0 rom /media
sr1 11:1 1 22.6M 0 rom /run/media/root/ytlab-ansible2.9_for-RHEL8.
nvme0n1 259:0 0 100G 0 disk
├─nvme0n1p1 259:1 0 512M 0 part /boot
├─nvme0n1p2 259:2 0 6G 0 part [SWAP]
└─nvme0n1p3 259:3 0 93.5G 0 part /[root@rhce ~]# mkdir /ansible_repo //建立挂载点
[root@rhce ~]# mount /dev/sr1 /ansible_repo/
[root@rhce ~]# vim /etc/yum.repos.d/rhel.repo
[ansible]
name=ansible
baseurl=file:///ansible_repo/ansible
enabled=1
gpgcheck=0
[root@rhce ~]# yum clean all[root@rhce ~]# yum makecache
[root@rhce ~]# yum -y install ansible //安装
[root@rhce ~]# 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, Mar 18 2021, 08:58:41) [GCC 8.4.1 20200928 (Red Hat 8.4.1-1)]
方法二、使用源码包编译安装
提取ansible.cfg的方法
通过此方法和方法三安装后都没有配置文件。
1、如果需要可以去github中搜索ansible.cfg找到后下载到/etc/ansible下使用就行了(手动安装目录都没有需要自己建)。
2、安装ansible包进入 安装目录中的ansible目录中找到ansible-2.9.11-1.el8ae.noarch.rpm
使用该命令提取rpm包中的文件:rpm2cpio ansible-2.9.11-1.el8ae.noarch.rpm | cpio -id
最后提取得到的就是下图中的ansible.cfg文件。
注:此处是将需要提取的rpm包拷贝到tmp中操作的,此处的etc目录也是提取文件后的目录并不是根下的etc目录。
ansible社区: https://github.com/ansible/ansible
下载地址:https://github.com/ansible/ansible/tree/v2.9.0
[root@test~]#wget https://ghproxy.com/https://github.com/ansible/ansible/archive/refs/tags/v2.9.0.zip
[root@test ~]# ls
anaconda-ks.cfg Documents initial-setup-ks.cfg Pictures Templates Videos
Desktop Downloads Music Public v2.9.0.zip[root@test ~]# du -sh v2.9.0.zip //查看下载的大小
27M v2.9.0.zip
[root@test ~]# unzip v2.9.0.zip //解压[root@test ~]# cd ansible-2.9.0/ //进入解压后的目录
[root@test ansible-2.9.0]# python3 setup.py build //构建包,不能直接进入setup.py修改
执行后会生成build的目录进入[root@test ansible-2.9.0]# cd build/
[root@test build]# ls
lib scripts-3.6
[root@test build]# cd scripts-3.6/
[root@test scripts-3.6]# ls //这些都是ansible的命令文件要把这些编译到系统中
ansible ansible-console ansible-inventory ansible-test
ansible-config ansible-doc ansible-playbook ansible-vault
ansible-connection ansible-galaxy ansible-pull这些文件就是一个一个的模块包
回到前两级目录解决这些文件的依赖关系
[root@test ansible-2.9.0]# python3 setup.py install //安装时会报一些错缺少相关包需要安装缺少的包后再进行安装
[root@test ansible-2.9.0]# yum install rust python3-jinja2 python3-cryptography -y
//根据安装时所报错的信息安装这几个包然后再重新安装(红帽8是这三个包每个版本报错不一样)
[root@test ansible-2.9.0]# python3 setup.py install
最后出现安装版本信息则成功Finished processing dependencies for ansible==2.9.0
[root@test ~]# ansible --version //查看安装的ansible信息
ansible 2.9.0
config file = None
configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/local/lib/python3.6/site-packages/ansible-2.9.0-py3.6.egg/ansible
executable location = /usr/local/bin/ansible
python version = 3.6.8 (default, Mar 18 2021, 08:58:41) [GCC 8.4.1 20200928 (Red Hat 8.4.1-1)]
方法三、使用python的pip包管理器进行安装
官方pypi的仓库:https://pypi.org/project/ansible
[root@test ~]# yum install python3-cryptography -y //安装依赖包(配置本地yum源)
[root@test ~]# pip3 install ansible==2.9.0 -i Simple Index //使用python的pypi的源安装ansible,==指定版本,如果不指定则是源中的最新版,后面的链接是指定的清华大学加速镜像站(红帽8需要指定pip版本)