wget安装ansible2.17【含python版本升级】

ansible有许多种安装方式,今天我们使用wget从github上下载安装包,由于ansible已经在17年开源,所以我们可以从github上面下载到所有版本的ansible安装包。

ansible源码包有两个版本:

1、官方社区开源版【一直在更新】,也是最新版所在的位置:

https://github.com/ansible/ansible

2、官方的稳定版本【注意:稳定版本只更新到2.9版本,之后版本请在官方社区下载】:

https://releases.ansible.com/

当前实验主机发行版本为:rehl9

且默认安装了“Development Tools”包组

[root@localhost ~]# dnf groupinstall "Development Tools" -y

官方社区下载

【注意:请先通过python -V命令查看自己的python版本,如果低于3.10,请跳转至‘升级python’处】

【请跟随图片上箭头指定的位置操作】 

【注:第二步选择版本可以依据个人需求来选择】

复制链接地址后,打开虚拟机,开始下载

[root@localhost ~]# ls
anaconda-ks.cfg  v2.17.0.zip  v2.17.0.zip.1
[root@localhost ~]# wget https://github.com/ansible/ansible/archive/refs/tags/v2.17.0.zip
--2024-07-09 21:14:47--  https://github.com/ansible/ansible/archive/refs/tags/v2.17.0.zip
Resolving github.com (github.com)... 20.205.243.166
Connecting to github.com (github.com)|20.205.243.166|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://codeload.github.com/ansible/ansible/zip/refs/tags/v2.17.0 [following]
--2024-07-09 21:14:48--  https://codeload.github.com/ansible/ansible/zip/refs/tags/v2.17.0
Resolving codeload.github.com (codeload.github.com)... 20.205.243.165
Connecting to codeload.github.com (codeload.github.com)|20.205.243.165|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [application/zip]
Saving to: ‘v2.17.0.zip’

v2.17.0.zip                                             [              <=>                                                                                                ]   5.36M  1.61MB/s    in 3.3s    

2024-07-09 21:14:52 (1.61 MB/s) - ‘v2.17.0.zip’ saved [5619774]

[root@localhost ~]# ll v2.17.0.zip 
-rw-r--r--. 1 root root 5619774 Jul  9 21:14 v2.17.0.zip


下载完毕后,我们就可以对他进行下一步操作了

【如果下载速度过慢,可以在github前加上kk,进行代理】

wget https://kkgithub.com/ansible/ansible/archive/refs/tags/v2.17.0.zip

先对这个源码包进行解压操作

[root@localhost ~]# mv v2.17.0.zip /opt/
[root@localhost ~]# cd /opt/
[root@localhost opt]# unzip v2.17.0.zip 
...【此处为系统解压过程,过于占篇幅,便不在此显示】

完成后,便可以在当前目录看到ansible解压文件

[root@localhost opt]# ls
ansible-2.17.0  v2.17.0.zip
[root@localhost opt]# cd ansible-2.17.0/
[root@localhost ansible-2.17.0]# ls
bin  changelogs  COPYING  hacking  lib  licenses  MANIFEST.in  packaging  pyproject.toml  README.md  requirements.txt  setup.cfg  **setup.py ** test

【注意这个setup.py这个文件,我们将基于它进行构建和安装】

[root@localhost ansible-2.17.0]# python setup.py build

[root@localhost ansible-2.17.0]# python setup.py install
当前命令执行后,中途会出现略微的停止,这是在读取网络源,所以等待即可,如果在停顿时执行失败,那么重复python setup.py install 这条命令即可
可以以create为标识,来观察是否处于当前状态


现在,让我们来查看ansible版本

[root@localhost ansible-2.17.0]# ansible --version
ERROR: Ansible requires Python 3.10 or newer on the controller. Current version: 3.9.10 (main, Feb  9 2022, 00:00:00) [GCC 11.2.1 20220127 (Red Hat 11.2.1-9)]
[root@localhost ansible-2.17.0]# python --version
Python 3.9.10 
出现报错,这个报错是为什么呢?
你的python版本过低
解决方法:升级python版本,或者重新安装ansible

升级python

我们想升级python版本来匹配当前ansible版本,我们就需要保证虚拟机可以上外网,可以尝试ping baidu.com 来测试。

[root@localhost ~]# ping baidu.com -w 3
PING baidu.com (110.242.68.66) 56(84) bytes of data.
64 bytes from 110.242.68.66 (110.242.68.66): icmp_seq=1 ttl=128 time=134 ms
64 bytes from 110.242.68.66 (110.242.68.66): icmp_seq=2 ttl=128 time=41.6 ms
64 bytes from 110.242.68.66 (110.242.68.66): icmp_seq=3 ttl=128 time=40.1 ms

--- baidu.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2005ms
rtt min/avg/max/mdev = 40.073/71.976/134.240/44.031 ms

当前我的主机是可以上外网的,那么现在我们开始升级python。

【请务必跟随清单顺序安装,如果顺序有误,有极大几率不可用!!!】

配置清单:

下载并解压所需软件包

【这里我使用最新版本的python3.12.4】

python3.12.4 、 setuptools、libffi、libffi-devel、ansible2.17.0

[root@localhost ~]# wget https://github.com/ansible/ansible/archive/refs/tags/v2.17.0.zip

[root@localhost ~]# wget https://github.com/libffi/libffi/releases/download/v3.4.5/libffi-3.4.5.tar.gz

[root@localhost ~]# wget https://files.pythonhosted.org/packages/65/d8/10a70e86f6c28ae59f101a9de6d77bf70f147180fbf40c3af0f64080adc3/setuptools-70.3.0.tar.gz

[root@localhost ~]# wget https://www.python.org/ftp/python/3.12.4/Python-3.12.4.tgz

下载完成后,对这四个包进行解压操作
[root@localhost ~]# tar -xzf Python-3.12.4.tgz
[root@localhost ~]# unzip v2.17.0.zip 
[root@localhost ~]# tar -xzf libffi-3.4.5.tar.gz 
[root@localhost ~]# tar -xzf setuptools-70.3.0.tar.gz 
[root@localhost ~]# ls
anaconda-ks.cfg  Desktop    Downloads     libffi-3.4.5.tar.gz  Pictures  Python-3.12.4      setuptools-70.3.0         Templates    Videos
ansible-2.17.0   Documents  libffi-3.4.5  Music                Public    Python-3.12.4.tgz  setuptools-70.3.0.tar.gz  v2.17.0.zip


开始安装【!!!一定要按顺序安装!!!】
安装中产生的信息,在本文中不会展示,执行命令后耐心等待即可。

【安装libffi】
[root@localhost ~]# cd libffi-3.4.5/
[root@localhost libffi-3.4.5]# ls
acinclude.m4   compile       configure.ac    fficonfig.h.in                         libffi.map.in     libtool-version     m4           makefile.sed~   msvc_build  testsuite
aclocal.m4     config.guess  configure.host  generate-darwin-source-and-headers.py  libffi.pc.in      LICENSE             Makefile     make_sunver.pl  msvcc.sh    x86_64-pc-linux-gnu
ChangeLog      config.sub    depcomp         include                                libffi.xcodeproj  LICENSE-BUILDTOOLS  Makefile.am  man             README.md
ChangeLog.old  configure     doc             install-sh                             libtool-ldflags   ltmain.sh           Makefile.in  missing         src
[root@localhost libffi-3.4.5]# ./configure
[root@localhost libffi-3.4.5]# make
[root@localhost libffi-3.4.5]# makeinstall

【安装libffi-devel】
[root@localhost ~]# dnf install libffi-devel -y

【安装python】
[root@localhost ~]# cd Python-3.12.4/
[root@localhost Python-3.12.4]# ls
aclocal.m4         config.guess   config.sub    Doc      install-sh       LICENSE   Makefile.pre     Modules  PC        Programs        pyconfig.h.in  python-config     README.rst
_bootstrap_python  config.log     configure     Grammar  Lib              Mac       Makefile.pre.in  Objects  PCbuild   pybuilddir.txt  python         python-config.py  Tools
build              config.status  configure.ac  Include  libpython3.12.a  Makefile  Misc             Parser   platform  pyconfig.h      Python         python-gdb.py
[root@localhost Python-3.12.4]# ./configure 
[root@localhost Python-3.12.4]# make all
[root@localhost Python-3.12.4]# make install
完成后,不必担心当前版本的问题,当前python版本不用删除
[root@localhost Python-3.12.4]# mv /usr/bin/python /usr/bin/python3.9.10
[root@localhost Python-3.12.4]# ln -s /usr/local/bin/python3 /usr/bin/python
[root@localhost Python-3.12.4]# python -V
Python 3.12.4

【安装ansible】
[root@localhost ansible-2.17.0]# python setup.py build
[root@localhost ansible-2.17.0]# python setup.py install





检查ansible版本和配置ansible.cfg文件
[root@localhost ansible-2.17.0]# ansible --version
ansible [core 2.17.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.12/site-packages/ansible_core-2.17.0-py3.12.egg/ansible
  ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/local/bin/ansible
  python version = 3.12.4 (main, Jul 10 2024, 19:51:04) [GCC 11.2.1 20220127 (Red Hat 11.2.1-9)] (/usr/bin/python)
  jinja version = 3.1.4
  libyaml = True
[root@localhost ansible-2.17.0]# ansible-config init --disabled -t all > ansible.cfg
[root@localhost ansible-2.17.0]# vim ansible.cfg 
[root@localhost ansible-2.17.0]# mkdir /etc/ansible
[root@localhost ansible-2.17.0]# mv ansible.cfg /etc/ansible/
[root@localhost ansible-2.17.0]# ansible --version
ansible [core 2.17.0]
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.12/site-packages/ansible_core-2.17.0-py3.12.egg/ansible
  ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/local/bin/ansible
  python version = 3.12.4 (main, Jul 10 2024, 19:51:04) [GCC 11.2.1 20220127 (Red Hat 11.2.1-9)] (/usr/bin/python)
  jinja version = 3.1.4
  libyaml = True

  
  

使用官方稳定版本下载

https://releases.ansible.com/

【进入当前网页,并跟随图片指引操作】

在当前页中,寻找到自己需要的版本

[root@localhost ~]# wget https://releases.ansible.com/ansible/ansible-2.9.0.tar.gz
--2024-07-10 10:57:19--  https://releases.ansible.com/ansible/ansible-2.9.0.tar.gz
Resolving releases.ansible.com (releases.ansible.com)... 104.26.1.234, 172.67.68.251, 104.26.0.234, ...
Connecting to releases.ansible.com (releases.ansible.com)|104.26.1.234|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 14126941 (13M) [application/x-gzip]
Saving to: ‘ansible-2.9.0.tar.gz’

ansible-2.9.0.tar.gz                                100%[================================================================================================================>]  13.47M  2.05MB/s    in 7.0s    

2024-07-10 10:57:27 (1.94 MB/s) - ‘ansible-2.9.0.tar.gz’ saved [14126941/14126941]

[root@localhost ~]# ls
anaconda-ks.cfg  ansible-2.9.0.tar.gz  Desktop  Documents  Downloads  Music  Pictures  Public  Templates  Videos

下载完毕后,对 ansible-2.9.0.tar.gz这个包进行解压缩操作

[root@localhost ~]# tar -xzf ansible-2.9.0.tar.gz 
[root@localhost ~]# ls
anaconda-ks.cfg  ansible-2.9.0  ansible-2.9.0.tar.gz  Desktop  Documents  Downloads  Music  Pictures  Public  Templates  Videos
[root@localhost ~]# cd ansible-2.9.0/
[root@localhost ansible-2.9.0]# ls
bin  changelogs  contrib  COPYING  docs  examples  hacking  lib  licenses  Makefile  MANIFEST.in  packaging  PKG-INFO  README.rst  requirements.txt ** setup.py  **shippable.yml  SYMLINK_CACHE.json  test

同样,还是要用python对他进行构建和安装

[root@localhost ansible-2.9.0]# python setup.py build
[root@localhost ansible-2.9.0]# python setup.py install

查看版本,并配置ansible.cfg

[root@localhost ~]# ansible --version
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.9/site-packages/ansible-2.9.0-py3.9.egg/ansible
  executable location = /usr/local/bin/ansible
  python version = 3.9.10 (main, Feb  9 2022, 00:00:00) [GCC 11.2.1 20220127 (Red Hat 11.2.1-9)]

[root@localhost ~]# cd ansible-2.9.0/
[root@localhost ansible-2.9.0]# cd examples/
[root@localhost examples]# ls
ansible.cfg  hosts  scripts
[root@localhost examples]# mkdir /etc/ansible
[root@localhost examples]# mv ansible.cfg /etc/ansible/
[root@localhost examples]# ansible --version
ansible 2.9.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.9/site-packages/ansible-2.9.0-py3.9.egg/ansible
  executable location = /usr/local/bin/ansible
  python version = 3.9.10 (main, Feb  9 2022, 00:00:00) [GCC 11.2.1 20220127 (Red Hat 11.2.1-9)]


ansible安装结束。

报错信息

如果出现当前报错

ERROR: No module named '_ctypes'

从libffi那里重新开始即可,切记,这几个安装包,一个都不能少。

  • 34
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值