将最新版本的Ansible 2.9安装到CentOS Stream 9上

确认 CentOS Stream 9 环境信息。

[root@syasuda-centos9 ~]# dnf update -y
[root@syasuda-centos9 ~]# cat /etc/redhat-release
CentOS Stream release 9
[root@syasuda-centos9 ~]# uname -a
Linux syasuda-centos9 5.14.0-361.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Aug 24 13:40:45 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

2. 安装pip

[root@syasuda-centos9 ~]# dnf install -y python3-pip

创建虚拟环境

为了避免在全局层面上更新pip可能对系统产生影响,建议在虚拟环境中配置并引入最新的Ansible 2.9模块。

[root@syasuda-centos9 ~]# python --version
Python 3.9.17
[root@syasuda-centos9 ~]# python -m venv env1
[root@syasuda-centos9 ~]# source env1/bin/activate

4. 安装和更新各种模块

更新pip到最新版本

(env1) [root@syasuda-centos9 ~]# pip install pip --upgrade

安装ansible2.9的最新版本

请参考以下链接:https://tekunabe.hatenablog.jp/entry/2020/12/05/ansible_29

(env1) [root@syasuda-centos9 ~]# pip install ansible~=2.9.0

4-3. 更新Jinja2至最新版

(env1) [root@syasuda-centos9 ~]# pip install Jinja2 --upgrade

参考にJinja2进行了最新更新,因为Ansible 2.9的boolean验证检查中出现了以下错误。为了解决这个问题,需要将Jinja2升级到最新版本。
https://github.com/robertdebock/ansible-role-tomcat/issues/37

TASK [validate_parms : Validate GUI flag] ********************************************************************************************************************************************
fatal: [localhost]: FAILED! => {"msg": "The conditional check 'setup_vsi_gui is boolean' failed. The error was: template error while templating string: no test named 'boolean'. String: {% if setup_vsi_gui is boolean %} True {% else %} False {% endif %}"}

4-4. SELinux的引入

(env1) [root@syasuda-centos9 ansible]# pip install selinux

为了避免在虚拟环境中发生类似SELinux操作的错误,可以考虑安装selinux,这样做似乎是个好主意。
参考链接:https://copyprogramming.com/howto/ansible-playbook-to-check-the-condition-of-selinux-status

TASK [start_sno_install : Create marker file] *************************************************************************************************************************************************************************************
fatal: [localhost]: FAILED! => {"changed": false, "msg": "Aborting, target uses selinux but python bindings (libselinux-python) aren't installed!"}

5. 最后的形式 de

(env1) [root@syasuda-centos9 ansible]#  pip list |grep -e pip -e ansible -e Jinja2 -e selinux
ansible      2.9.27
Jinja2       3.1.2
pip          23.2.1
selinux      0.3.0

(env1) [root@syasuda-centos9 ~]# ansible --version
ansible 2.9.27
  config file = None
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /root/env1/lib64/python3.9/site-packages/ansible
  executable location = /root/env1/bin/ansible
  python version = 3.9.17 (main, Aug  9 2023, 00:00:00) [GCC 11.4.1 20230605 (Red Hat 11.4.1-2)]
广告
将在 10 秒后关闭
bannerAds