本章内容主要介绍RHEL8中如何安装ansible?
[root@node01 ~]# yum -y groupinstall 开发工具
[root@node01 ~]# mount /dev/cdrom /mnt/
mount: /mnt: /dev/sr0 already mounted on /var/ftp/dvd.
[root@node01 ~]#
[root@node01 ~]# cat /etc/yum.repos.d/aa.repo
[aa]
name=aa
baseurl=file:///mnt/AppStream
enabled=1
gpgcheck=0
[bb]
name=bb
baseurl=///mnt/BaseOS
enabled=1
gpgcheck=0
[root@node01 ~]#
[root@node01 ~]# yum -y install https://mirrors.aliyun.com/epel/epel-release-latest-8.noarch.rpm
[root@node01 ~]# sed -i 's|^#baseurl=https://download.fedoraproject.org/pub|baseurl=https://mirrors.aliyun.com|' /etc/yum.repos.d/epel*
[root@node01 ~]# sed -i 's|^metalink|#metalink|' /etc/yum.repos.d/epel*
[root@node01 ~]# wget https://www.python.org/ftp/python/3.12.1/Python-3.12.1.tgz
[root@node01 ~]# tar -zxvf Python-3.12.1.tgz
[root@node01 ~]# dnf -y install gcc zlib* libffi-devel
[root@node01 Python-3.12.1]# cd Python-3.12.1/
[root@node01 Python-3.12.1]# ./configure --prefix=/usr/local/python3 --enable-optimizations
[root@node01 Python-3.12.1]# make
[root@node01 Python-3.12.1]# make install
[root@node01 Python-3.12.1]# rm -rf /usr/bin/python3
[root@node01 Python-3.12.1]# ln -s /usr/local/python3/bin/python3 /usr/bin/python3
[root@node01 Python-3.12.1]# rm -rf /usr/bin/pip3
[root@node01 Python-3.12.1]# ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
[root@node01 ~]# python3 --version
Python 3.12.1
[root@node01 ~]# pip3 --version
pip 23.2.1 from /usr/local/python3/lib/python3.12/site-packages/pip (python 3.12)
[root@node01 ~]#
[root@node01 ~]# 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 需要
[root@node01 ~]#
错误:依赖检测失败:
?? ?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源就可以解决了
[root@node01 ~]# yum -y install python3-cryptography
[root@node01 ~]# yum -y install python3-jinja2
[root@node01 ~]# rpm -ivh sshpass-1.06-3.el8ae.x86_64.rpm
[root@node01 ~]# rpm -ivh ansible-2.9.11-1.el8ae.noarch.rpm
Verifying... ################################# [100%]
准备中... ################################# [100%]
正在升级/安装...
1:ansible-2.9.11-1.el8ae ################################# [100%]
[root@node01 ~]#
[root@node01 ~]# 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@node01 ~]# pip3 --version
pip 23.2.1 from /usr/local/python3/lib/python3.12/site-packages/pip (python 3.12)
[root@node01 ~]#
[root@node01 ~]# cat /etc/hosts | grep node
192.168.182.220 node02
192.168.182.210 node03
[root@node01 ~]#
[root@node02 ~]# cat /etc/sudoers.d/blab
blab ALL=(root) NOPASSWD: ALL
[root@node02 ~]#
[root@node01 ~]# cat /etc/sudoers.d/blab
blab ALL=(root) NOPASSWD: ALL
[root@node01 ~]#
[root@node02 ~]# ssh 192.168.182.200
Activate the web console with: systemctl enable --now cockpit.socket
This system is not registered to Red Hat Insights. See https://cloud.redhat.com/
To register this system, run: insights-client --register
Last login: Thu Dec 14 08:23:08 2023 from 192.168.182.1
[root@node01 ~]# exit
注销
Connection to 192.168.182.200 closed.
[root@node02 ~]#