1、安装Python 3.x环境
[root@ansible ~]# yum install -y python36 python36-pip git [root@ansible ~]# ln -s /usr/bin/pip36 /usr/bin/pip3 [root@ansible ~]# pip install virtualenv
2、配置virtualenv环境(可选)
[deploy@ansible ~]$ useradd deploy && su - deploy [deploy@ansible ~]$ virtualenv -p /bin/python3.6 .py3-a2.5-env [deploy@ansible ~]$ source .py3-a2.5-env/bin/activate
3、从Github下载最新稳定版本代码
[root@localhost ~]# git clone -b stable-2.7 https://github.com/ansible/ansible.git Cloning into 'ansible'... remote: Enumerating objects: 2, done. remote: Counting objects: 100% (2/2), done. remote: Compressing objects: 100% (2/2), done. remote: Total 426337 (delta 1), reused 0 (delta 0), pack-reused 426335 Receiving objects: 100% (426337/426337), 155.97 MiB | 4.54 MiB/s, done. Resolving deltas: 100% (276264/276264), done.
4、安装ansible Python依赖包
[root@localhost ~]# pip3 install paramiko PyYAML jinja2 Collecting paramiko Downloading https://files.pythonhosted.org/packages/cf/ae/94e70d49044ccc234bfdba20114fa947d7ba6eb68a2e452d89b920e62227/paramiko-2.4.2-py2.py3-none-any.whl (193kB) 100% |████████████████████████████████| 194kB 976kB/s Collecting PyYAML Downloading https://files.pythonhosted.org/packages/9f/2c/9417b5c774792634834e730932745bc09a7d36754ca00acf1ccd1ac2594d/PyYAML-5.1.tar.gz (274kB) 100% |████████████████████████████████| 276kB 3.2MB/s Collecting jinja2 Downloading https://files.pythonhosted.org/packages/1d/e7/fd8b501e7a6dfe492a433deb7b9d833d39ca74916fa8bc63dd1a4947a671/Jinja2-2.10.1-py2.py3-none-any.whl (124kB) 100% |████████████████████████████████| 133kB 6.3MB/s Collecting pyasn1>=0.1.7 (from paramiko) Downloading https://files.pythonhosted.org/packages/7b/7c/c9386b82a25115cccf1903441bba3cbadcfae7b678a20167347fa8ded34c/pyasn1-0.4.5-py2.py3-none-any.whl (73kB) 100% |████████████████████████████████| 81kB 7.8MB/s Collecting bcrypt>=3.1.3 (from paramiko) Downloading https://files.pythonhosted.org/packages/d0/79/79a4d167a31cc206117d9b396926615fa9c1fdbd52017bcced80937ac501/bcrypt-3.1.6-cp34-abi3-manylinux1_x86_64.whl (55kB) 100% |████████████████████████████████| 61kB 6.6MB/s Collecting cryptography>=1.5 (from paramiko) Downloading https://files.pythonhosted.org/packages/5b/12/b0409a94dad366d98a8eee2a77678c7a73aafd8c0e4b835abea634ea3896/cryptography-2.6.1-cp34-abi3-manylinux1_x86_64.whl (2.3MB) 100% |████████████████████████████████| 2.3MB 506kB/s Collecting pynacl>=1.0.1 (from paramiko) Downloading https://files.pythonhosted.org/packages/27/15/2cd0a203f318c2240b42cd9dd13c931ddd61067809fee3479f44f086103e/PyNaCl-1.3.0-cp34-abi3-manylinux1_x86_64.whl (759kB) 100% |████████████████████████████████| 768kB 1.6MB/s Collecting MarkupSafe>=0.23 (from jinja2) Downloading https://files.pythonhosted.org/packages/b2/5f/23e0023be6bb885d00ffbefad2942bc51a620328ee910f64abe5a8d18dd1/MarkupSafe-1.1.1-cp36-cp36m-manylinux1_x86_64.whl Collecting cffi>=1.1 (from bcrypt>=3.1.3->paramiko) Downloading https://files.pythonhosted.org/packages/20/f7/87b62a8895bf7c93e907b05b97bc4459c81a38a61151f03a6eae13d863aa/cffi-1.12.2-cp36-cp36m-manylinux1_x86_64.whl (428kB) 100% |████████████████████████████████| 430kB 3.0MB/s Collecting six>=1.4.1 (from bcrypt>=3.1.3->paramiko) Downloading https://files.pythonhosted.org/packages/73/fb/00a976f728d0d1fecfe898238ce23f502a721c0ac0ecfedb80e0d88c64e9/six-1.12.0-py2.py3-none-any.whl Collecting asn1crypto>=0.21.0 (from cryptography>=1.5->paramiko) Downloading https://files.pythonhosted.org/packages/ea/cd/35485615f45f30a510576f1a56d1e0a7ad7bd8ab5ed7cdc600ef7cd06222/asn1crypto-0.24.0-py2.py3-none-any.whl (101kB) 100% |████████████████████████████████| 102kB 6.6MB/s Collecting pycparser (from cffi>=1.1->bcrypt>=3.1.3->paramiko) Downloading https://files.pythonhosted.org/packages/68/9e/49196946aee219aead1290e00d1e7fdeab8567783e83e1b9ab5585e6206a/pycparser-2.19.tar.gz (158kB) 100% |████████████████████████████████| 163kB 5.5MB/s Installing collected packages: pyasn1, pycparser, cffi, six, bcrypt, asn1crypto, cryptography, pynacl, paramiko, PyYAML, MarkupSafe, jinja2 Running setup.py install for pycparser ... done Running setup.py install for PyYAML ... done Successfully installed MarkupSafe-1.1.1 PyYAML-5.1 asn1crypto-0.24.0 bcrypt-3.1.6 cffi-1.12.2 cryptography-2.6.1 jinja2-2.10.1 paramiko-2.4.2 pyasn1-0.4.5 pycparser-2.19 pynacl-1.3.0 six-1.12.0 You are using pip version 9.0.1, however version 19.0.3 is available. You should consider upgrading via the 'pip install --upgrade pip' command.
5、安装ansible
[root@localhost ~]# ls ansible [root@localhost ~]# cd ansible/ [root@localhost ansible]# ls bin contrib docsite_requirements.txt lib MANIFEST.in README.rst shippable.yml changelogs COPYING examples licenses MODULE_GUIDELINES.md requirements.txt test CODING_GUIDELINES.md docs hacking Makefile packaging setup.py tox.ini [root@localhost ansible]# python3 setup.py install running install running bdist_egg running egg_info creating lib/ansible.egg-info writing lib/ansible.egg-info/PKG-INFO writing dependency_links to lib/ansible.egg-info/dependency_links.txt writing requirements to lib/ansible.egg-info/requires.txt writing top-level names to lib/ansible.egg-info/top_level.txt writing manifest file 'lib/ansible.egg-info/SOURCES.txt' reading manifest file 'lib/ansible.egg-info/SOURCES.txt' reading manifest template 'MANIFEST.in' warning: no files found matching 'SYMLINK_CACHE.json' writing manifest file 'lib/ansible.egg-info/SOURCES.txt' installing library code to build/bdist.linux-x86_64/egg running install_lib running build_py . . 此处省略几百行 . . Using /usr/local/lib/python3.6/site-packages Finished processing dependencies for ansible==2.7.10.post0
6、创建Ansible配置文件,并开启Ansible日志(Ansible默认不启用日志)
[root@localhost ~]# mkdir /etc/ansible [root@localhost ~]# cp ansible/examples/ansible.cfg /etc/ansible/ [root@localhost ~]# sed -i 's/#log_path/log_path/' /etc/ansible/ansible.cfg
7、验证Ansible安装结果
[root@localhost ansible]# ansible --version ansible 2.7.10.post0 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-2.7.10.post0-py3.6.egg/ansible executable location = /usr/local/bin/ansible python version = 3.6.2 (default, Apr 7 2019, 01:01:39) [GCC 4.8.5 20150623 (Red Hat 4.8.5-36)]