Centos7.9 安装 Ansible
前置条件
- epel.repo
- python3.8+
升级过程
安装epel.repo
- 使用 yum install
[16:46:46] root@ansible-server:/etc/yum.repos.d # yum install epel-release 已加载插件:fastestmirror, langpacks Loading mirror speeds from cached hostfile 正在解决依赖关系 --> 正在检查事务 ---> 软件包 epel-release.noarch.0.7-14 将被 安装 --> 解决依赖关系完成 依赖关系解决 ============================================================================================================================================================================================================ Package 架构 版本 源 大小 ============================================================================================================================================================================================================ 正在安装: epel-release noarch 7-14 epel 15 k 事务概要 ============================================================================================================================================================================================================ 安装 1 软件包 总下载量:15 k 安装大小:25 k Is this ok [y/d/N]: y Downloading packages: epel-release-7-14.noarch.rpm | 15 kB 00:00:00 Running transaction check Running transaction test Transaction test succeeded Running transaction 正在安装 : epel-release-7-14.noarch 1/1 验证中 : epel-release-7-14.noarch 1/1 已安装: epel-release.noarch 0:7-14 完毕!
安装 Python
- 下载python
wget https://www.python.org/ftp/python/3.9.16/Python-3.9.16.tgz
- 解压包
tar -xvf Python-3.9.16.tgz && cd Python-3.9.16
-
编译
./configure
- 安装
make -j2 && make install
升级 Ansible
- 确认pip
[17:24:16] root@ansible-server:~ # python3 -m pip -V pip 23.0.1 from /usr/local/lib/python3.10/site-packages/pip (python 3.10)
- 如果显示没有安装pip,如下
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py python3 get-pip.py --user
- 升级pip
[17:29:54] root@ansible-server:~ # pip3 install --upgrade pip Looking in indexes: http://mirrors.tencentyun.com/pypi/simple Requirement already satisfied: pip in /usr/local/lib/python3.10/site-packages (23.0.1) Collecting pip Downloading http://mirrors.tencentyun.com/pypi/packages/08/e3/57d4c24a050aa0bcca46b2920bff40847db79535dc78141eb83581a52eb8/pip-23.1.2-py3-none-any.whl (2.1 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2.1/2.1 MB 1.7 MB/s eta 0:00:00 Installing collected packages: pip Attempting uninstall: pip Found existing installation: pip 23.0.1 Uninstalling pip-23.0.1: Successfully uninstalled pip-23.0.1 Successfully installed pip-23.1.2 WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv [17:30:18] root@ansible-server:~ # python3 -m pip -V pip 23.1.2 from /usr/local/lib/python3.10/site-packages/pip (python 3.10)
- 升级ansible
[17:31:35] root@ansible-server:~ # python3 -m pip install --user ansible Looking in indexes: http://mirrors.tencentyun.com/pypi/simple Requirement already satisfied: ansible in ./.local/lib/python3.10/site-packages (8.0.0) Requirement already satisfied: ansible-core~=2.15.0 in ./.local/lib/python3.10/site-packages (from ansible) (2.15.0) Requirement already satisfied: jinja2>=3.0.0 in ./.local/lib/python3.10/site-packages (from ansible-core~=2.15.0->ansible) (3.1.2) Requirement already satisfied: PyYAML>=5.1 in ./.local/lib/python3.10/site-packages (from ansible-core~=2.15.0->ansible) (6.0) Requirement already satisfied: cryptography in ./.local/lib/python3.10/site-packages (from ansible-core~=2.15.0->ansible) (41.0.1) Requirement already satisfied: packaging in ./.local/lib/python3.10/site-packages (from ansible-core~=2.15.0->ansible) (23.1) Requirement already satisfied: resolvelib<1.1.0,>=0.5.3 in ./.local/lib/python3.10/site-packages (from ansible-core~=2.15.0->ansible) (1.0.1) Requirement already satisfied: MarkupSafe>=2.0 in ./.local/lib/python3.10/site-packages (from jinja2>=3.0.0->ansible-core~=2.15.0->ansible) (2.1.3) Requirement already satisfied: cffi>=1.12 in ./.local/lib/python3.10/site-packages (from cryptography->ansible-core~=2.15.0->ansible) (1.15.1) Requirement already satisfied: pycparser in ./.local/lib/python3.10/site-packages (from cffi>=1.12->cryptography->ansible-core~=2.15.0->ansible) (2.21) WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
- 提示警告是因为你正在使用
root
用户身份运行pip
命令,这可能会导致权限问题和与系统软件包管理器的冲突[17:31:42] root@ansible-server:~ # pip3 install virtualenv Looking in indexes: http://mirrors.tencentyun.com/pypi/simple Collecting virtualenv Downloading http://mirrors.tencentyun.com/pypi/packages/f1/0a/18755fa6aec794fd539b050beeaa905fa5c77c64356aa8bdecb62c01581a/virtualenv-20.23.0-py3-none-any.whl (3.3 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 3.3/3.3 MB 2.3 MB/s eta 0:00:00 Collecting distlib<1,>=0.3.6 (from virtualenv) Using cached http://mirrors.tencentyun.com/pypi/packages/76/cb/6bbd2b10170ed991cf64e8c8b85e01f2fb38f95d1bc77617569e0b0b26ac/distlib-0.3.6-py2.py3-none-any.whl (468 kB) Collecting filelock<4,>=3.11 (from virtualenv) Downloading http://mirrors.tencentyun.com/pypi/packages/ad/73/b094a662ae05cdc4ec95bc54e434e307986a5de5960166b8161b7c1373ee/filelock-3.12.0-py3-none-any.whl (10 kB) Collecting platformdirs<4,>=3.2 (from virtualenv) Downloading http://mirrors.tencentyun.com/pypi/packages/89/7e/c6ff9ddcf93b9b36c90d88111c4db354afab7f9a58c7ac3257fa717f1268/platformdirs-3.5.1-py3-none-any.whl (15 kB) Installing collected packages: distlib, platformdirs, filelock, virtualenv Successfully installed distlib-0.3.6 filelock-3.12.0 platformdirs-3.5.1 virtualenv-20.23.0 WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
- 提示警告 ModuleNotFoundError: No module named '_ssl'