首先在一个Online 的CentOS Stream 8 上把需要的安装包下载下来,然后再拷贝到离线的主机上进行安装。
下载工具推荐用 python pip 来下载,这样在安装的时候也用pip来安装就很简单了。这里唯一需要准备的是一个和离线环境相同的系统,可以通过docker来实现,就不展示了。
首先 ansible 4.2.0的安装依赖pip的版本比较高,CentOS Stream 8默认的pip版本是 pip 9.0.3 , 所以先下载pip的升级包
[root@localhost ~]# more requirements_pip.txt
pip==21.3.1
[root@localhost ~]# python3 -m pip download -r requirements_pip.txt -d /root/mypackages/pip
Collecting pip==21.3.1 (from -r requirements_pip.txt (line 1))
Downloading https://files.pythonhosted.org/packages/a4/6d/6463d49a933f547439d6b5b98b46af8742cc03ae83543e4d7688c2420f8b/pip-21.3.1-py3-none-any.whl (1.7MB)
100% |████████████████████████████████| 1.7MB 102kB/s
Saved ./mypackages/pip/pip-21.3.1-py3-none-any.whl
Successfully downloaded pip
先在Online的主机上升级pip,不然下载ansible4.2.0也会报错。
[root@localhost ~]# python3 -m pip install --no-index --find-links /root/mypackages/pip -r requirements_pip.txt
WARNING: Running pip install with root privileges is generally not a good idea. Try `__main__.py install --user` instead.
Collecting pip==21.3.1 (from -r requirements_pip.txt (line 1))
Installing collected packages: pip
Successfully installed pip-21.3.1
[root@localhost ~]# python3 -m pip --version
pip 21.3.1 from /usr/local/lib/python3.6/site-packages/pip (python 3.6)
然后开始下载ansible4.2.0
[root@localhost ~]# more requirements.txt
ansible==4.2.0
[root@localhost ~]# mkdir -p /root/mypackages/ansible
[root@localhost ~]# python3 -m pip download -r requirements.txt -d /root/mypackages/ansible
Collecting ansible==4.2.0
File was already downloaded /root/mypackages/ansible-4.2.0.tar.gz
Preparing metadata (setup.py) ... done
Collecting ansible-core<2.12,>=2.11.2
File was already downloaded /root/mypackages/ansible-core-2.11.12.tar.gz
Preparing metadata (setup.py) ... done
Collecting jinja2
File was already downloaded /root/mypackages/Jinja2-3.0.3-py3-none-any.whl
Collecting PyYAML
File was already downloaded /root/mypackages/PyYAML-6.0-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Collecting cryptography
Downloading cryptography-39.0.0-cp36-abi3-manylinux_2_28_x86_64.whl (4.2 MB)
|████████████████████████████████| 4.2 MB 1.1 MB/s
Collecting packaging
Downloading packaging-21.3-py3-none-any.whl (40 kB)
|████████████████████████████████| 40 kB 1.2 MB/s
Collecting resolvelib<0.6.0,>=0.5.3
Downloading resolvelib-0.5.4-py2.py3-none-any.whl (12 kB)
Collecting cffi>=1.12
Downloading cffi-1.15.1-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.whl (402 kB)
|████████████████████████████████| 402 kB 743 kB/s
Collecting MarkupSafe>=2.0
Downloading MarkupSafe-2.0.1-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (30 kB)
Collecting pyparsing!=3.0.5,>=2.0.2
Downloading pyparsing-3.0.9-py3-none-any.whl (98 kB)
|████████████████████████████████| 98 kB 1.2 MB/s
Collecting pycparser
Downloading pycparser-2.21-py2.py3-none-any.whl (118 kB)
|████████████████████████████████| 118 kB 1.3 MB/s
Saved ./mypackages/resolvelib-0.5.4-py2.py3-none-any.whl
Saved ./mypackages/cryptography-39.0.0-cp36-abi3-manylinux_2_28_x86_64.whl
Saved ./mypackages/packaging-21.3-py3-none-any.whl
Saved ./mypackages/cffi-1.15.1-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.whl
Saved ./mypackages/MarkupSafe-2.0.1-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Saved ./mypackages/pyparsing-3.0.9-py3-none-any.whl
Saved ./mypackages/pycparser-2.21-py2.py3-none-any.whl
Successfully downloaded ansible ansible-core resolvelib cryptography jinja2 packaging PyYAML cffi MarkupSafe pyparsing pycparser
[root@localhost ~]# ll mypackages/ansible/
total 46616
-rw-r--r--. 1 root root 34966129 Jan 8 01:40 ansible-4.2.0.tar.gz
-rw-r--r--. 1 root root 7118115 Jan 8 01:40 ansible-core-2.11.12.tar.gz
-rw-r--r--. 1 root root 402952 Jan 8 01:40 cffi-1.15.1-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.whl
-rw-r--r--. 1 root root 4189829 Jan 8 01:40 cryptography-39.0.0-cp36-abi3-manylinux_2_28_x86_64.whl
-rw-r--r--. 1 root root 133630 Jan 8 01:40 Jinja2-3.0.3-py3-none-any.whl
-rw-r--r--. 1 root root 30247 Jan 8 01:40 MarkupSafe-2.0.1-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
-rw-r--r--. 1 root root 40750 Jan 8 01:40 packaging-21.3-py3-none-any.whl
-rw-r--r--. 1 root root 118697 Jan 8 01:40 pycparser-2.21-py2.py3-none-any.whl
-rw-r--r--. 1 root root 98338 Jan 8 01:40 pyparsing-3.0.9-py3-none-any.whl
-rw-r--r--. 1 root root 603963 Jan 8 01:40 PyYAML-6.0-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
-rw-r--r--. 1 root root 12807 Jan 8 01:40 resolvelib-0.5.4-py2.py3-none-any.whl
现在本地安装ansible4.2.0验证是否成功
[root@localhost ~]# python3 -m pip install --no-index --find-links /root/mypackages/ansible -r requirements.txt
Looking in links: /root/mypackages/ansible
Processing ./mypackages/ansible/ansible-4.2.0.tar.gz
Preparing metadata (setup.py) ... done
Processing ./mypackages/ansible/ansible-core-2.11.12.tar.gz
Preparing metadata (setup.py) ... done
Processing ./mypackages/ansible/Jinja2-3.0.3-py3-none-any.whl
Requirement already satisfied: PyYAML in /usr/lib64/python3.6/site-packages (from ansible-core<2.12,>=2.11.2->ansible==4.2.0->-r requirements.txt (line 1)) (3.12)
Processing ./mypackages/ansible/cryptography-39.0.0-cp36-abi3-manylinux_2_28_x86_64.whl
Processing ./mypackages/ansible/packaging-21.3-py3-none-any.whl
Processing ./mypackages/ansible/resolvelib-0.5.4-py2.py3-none-any.whl
Processing ./mypackages/ansible/cffi-1.15.1-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.whl
Processing ./mypackages/ansible/MarkupSafe-2.0.1-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Processing ./mypackages/ansible/pyparsing-3.0.9-py3-none-any.whl
Processing ./mypackages/ansible/pycparser-2.21-py2.py3-none-any.whl
Using legacy 'setup.py install' for ansible, since package 'wheel' is not installed.
Using legacy 'setup.py install' for ansible-core, since package 'wheel' is not installed.
Installing collected packages: pycparser, pyparsing, MarkupSafe, cffi, resolvelib, packaging, jinja2, cryptography, ansible-core, ansible
Running setup.py install for ansible-core ... done
Running setup.py install for ansible ... done
Successfully installed MarkupSafe-2.0.1 ansible-4.2.0 ansible-core-2.11.12 cffi-1.15.1 cryptography-39.0.0 jinja2-3.0.3 packaging-21.3 pycparser-2.21 pyparsing-3.0.9 resolvelib-0.5.4
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@localhost ~]# ansible --version
[DEPRECATION WARNING]: Ansible will require Python 3.8 or newer on the controller starting with Ansible 2.12. Current version: 3.6.8 (default, Jun 23 2022, 19:01:59) [GCC 8.5.0 20210514 (Red
Hat 8.5.0-13)]. This feature will be removed from ansible-core in version 2.12. Deprecation warnings can be disabled by setting deprecation_warnings=False in ansible.cfg.
/usr/local/lib/python3.6/site-packages/ansible/parsing/vault/__init__.py:44: CryptographyDeprecationWarning: Python 3.6 is no longer supported by the Python core team. Therefore, support for it is deprecated in cryptography. The next release of cryptography (40.0) will be the last to support Python 3.6.
from cryptography.exceptions import InvalidSignature
ansible [core 2.11.12]
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
ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/local/bin/ansible
python version = 3.6.8 (default, Jun 23 2022, 19:01:59) [GCC 8.5.0 20210514 (Red Hat 8.5.0-13)]
jinja version = 3.0.3
libyaml = True
以上验证成功,说明安装包可以使用,直接拷贝到Offline的主机上进行安装就行了。
标签:CentOS,Stream,whl,离线,ansible,64,pip,root,x86 From: https://www.cnblogs.com/yuedu/p/17034731.html