redhat7.4+ansible2.4.3.0离线安装指南,
redhat7.4+ansible2.4.3.0离线安装指南,
ansible离线安装指南
1 前言
RHEL Linux环境ansible的安装在有Internet网络环境的情况下,可以通过pip、部署yum源后使用yum安装或者采用离线包安装集中方式进行,在没有网络环境的情况下,一般只能采用离线包安装,本文即介绍这种安装方式。本文作者cdshrewd不保证该方式符合最佳实践,只记录作者的实验过程,如有疑问请联系:cdshrewd@163.com.
2 基础环境说明及准备
本次测试涉及两台服务器,一台是控制机,一台是被控测试机。相关信息如下:
控制机
被控测试机
机器名
ansible01
ansible02
IP
192.168.2.20
192.168.2.30
操作系统版本
Red Hat Enterprise Linux Server release 7.4 (Maipo)
Red Hat Enterprise Linux Server release 7.4 (Maipo)
ansible软件位置
/opt/ansible
N/A
python版本
Python 2.7.5
Python 2.7.5
ansible版本
2.4.3.0
N/A
ansible相关软件包及版本信息如下:
ansible-2.4.3.0
asn1crypto-0.24.0
bcrypt-3.1.4
cffi-1.11.4
cryptography-2.0.3
ecdsa-0.13
enum34-1.1.6
idna-2.6
ipaddress-1.0.19
Jinja2-2.9.6
markupsafe-master
paramiko-2.3.0
pyasn1-0.4.2
pycparser-2.18
pycrypto-2.6.1
PyNaCl-1.2.1
PyYAML-3.12
setuptools-36.5.0
simplejson-3.13.2
sshpass-1.06
yaml-0.1.7
操作系统需要安装的rpm包主要有以下几个,建议采用yum安装:
gcc
python-devel
openssl-devel
libffi-devel
zlib-devel
libyaml
3 ansible及相关包安装
3.1 离线文件上传
将所有以下安装包上传到/opt/ansible目录下。
ansible-2.4.3.0.tar.gz
asn1crypto-0.24.0.tar.gz
bcrypt-3.1.4.tar.gz
cffi-1.11.4.tar.gz
cryptography-2.0.3.tar.gz
ecdsa-0.13.tar.gz
enum34-1.1.6.tar.gz
idna-2.6.tar.gz
ipaddress-1.0.19.tar.gz
Jinja2-2.9.6.tar.gz
markupsafe-master.zip
paramiko-2.3.0.tar.gz
pyasn1-0.4.2.tar.gz
pycparser-2.18.tar.gz
pycrypto-2.6.1.tar.gz
PyNaCl-1.2.1.tar.gz
PyYAML-3.12.tar.gz
setuptools-36.5.0.zip
simplejson-3.13.2.tar.gz
sshpass-1.06.tar.gz
yaml-0.1.7.tar.gz
3.2 依赖包安装
setuptools
cd /opt/ansible
unzip setuptools-36.5.0.zip
cd setuptools-36.5.0
python setup.py install
pycrypto
cd /opt/ansible
tar -xzvf pycrypto-2.6.1.tar.gz
cd pycrypto-2.6.1
python setup.py install
yaml
cd /opt/ansible
tar -xzvf yaml-0.1.7.tar.gz
cd yaml-0.1.7
./configure
make --jobs=`grep processor/proc/cpuinfo | wc -l`
make install
PyYAML
cd /opt/ansible
tar -xzvf PyYAML-3.12.tar.gz
cd PyYAML-3.12
python setup.py install
MarkupSafe
cd /opt/ansible
unzip markupsafe-master.zip
cd markupsafe-master
python setup.py install
ecdsa
cd /opt/ansible
tar -xzvf ecdsa-0.13.tar.gz
cd ecdsa-0.13
python setup.py install
pyasn1
cd /opt/ansible
tar -xzvf pyasn1-0.4.2.tar.gz
cd pyasn1-0.4.2
python setup.py install
pycparser
cd /opt/ansible
tar -xzvf pycparser-2.18.tar.gz
cd pycparser-2.18
python setup.py install
cffi
cd /opt/ansible
tar -xzvf cffi-1.11.4.tar.gz
cd cffi-1.11.4
python setup.py install
PyNaCl
cd /opt/ansible
tar -xzvf PyNaCl-1.2.1.tar.gz
cd PyNaCl-1.2.1
python setup.py install
ipaddress
cd /opt/ansible
tar -xzvfipaddress-1.0.19.tar.gz
cd ipaddress-1.0.19
python setup.py install
enum34
cd /opt/ansible
tar -xzvf enum34-1.1.6.tar.gz
cd enum34-1.1.6
python setup.py install
asn1crypto
cd /opt/ansible
tar -xzvfasn1crypto-0.24.0.tar.gz
cd asn1crypto-0.24.0
python setup.py install
idna
cd /opt/ansible
tar -xzvf idna-2.6.tar.gz
cd idna-2.6
python setup.py install
cryptography
cd /opt/ansible
tar -xzvfcryptography-2.0.3.tar.gz
cd cryptography-2.0.3
python setup.py install
bcrypt
cd /opt/ansible
tar -xzvf bcrypt-3.1.4.tar.gz
cd bcrypt-3.1.4
python setup.py install
paramiko
cd /opt/ansible
tar -xzvf paramiko-2.3.0.tar.gz
cd paramiko-2.3.0
python setup.py install
simplejson
cd /opt/ansible
tar -xzvf simplejson-3.13.2.tar.gz
cd simplejson-3.13.2
python setup.py install
3.3 安装ansible
cd /opt/ansible
tar -xzvf ansible-2.4.3.0.tar.gz
cd ansible-2.4.3.0
python setup.py install
...
byte-compilingbuild/bdist.linux-x86_64/egg/ansible/utils/module_docs_fragments/oneview.py tooneview.pyc
byte-compiling build/bdist.linux-x86_64/egg/ansible/utils/module_docs_fragments/openstack.pyto openstack.pyc
byte-compilingbuild/bdist.linux-x86_64/egg/ansible/utils/module_docs_fragments/openswitch.pyto openswitch.pyc
byte-compilingbuild/bdist.linux-x86_64/egg/ansible/utils/module_docs_fragments/ovirt.py toovirt.pyc
byte-compilingbuild/bdist.linux-x86_64/egg/ansible/utils/module_docs_fragments/ovirt_facts.pyto ovirt_facts.pyc
byte-compilingbuild/bdist.linux-x86_64/egg/ansible/utils/module_docs_fragments/postgres.py topostgres.pyc
byte-compilingbuild/bdist.linux-x86_64/egg/ansible/utils/module_docs_fragments/purestorage.pyto purestorage.pyc
byte-compilingbuild/bdist.linux-x86_64/egg/ansible/utils/module_docs_fragments/rackspace.pyto rackspace.pyc
byte-compiling build/bdist.linux-x86_64/egg/ansible/utils/module_docs_fragments/return_common.pyto return_common.pyc
byte-compilingbuild/bdist.linux-x86_64/egg/ansible/utils/module_docs_fragments/sros.py tosros.pyc
byte-compiling build/bdist.linux-x86_64/egg/ansible/utils/module_docs_fragments/tower.pyto tower.pyc
byte-compilingbuild/bdist.linux-x86_64/egg/ansible/utils/module_docs_fragments/validate.py tovalidate.pyc
byte-compilingbuild/bdist.linux-x86_64/egg/ansible/utils/module_docs_fragments/vca.py tovca.pyc
byte-compilingbuild/bdist.linux-x86_64/egg/ansible/utils/module_docs_fragments/vmware.py tovmware.pyc
byte-compilingbuild/bdist.linux-x86_64/egg/ansible/utils/module_docs_fragments/vyos.py tovyos.pyc
byte-compiling build/bdist.linux-x86_64/egg/ansible/vars/__init__.pyto __init__.pyc
byte-compilingbuild/bdist.linux-x86_64/egg/ansible/vars/hostvars.py to hostvars.pyc
byte-compilingbuild/bdist.linux-x86_64/egg/ansible/vars/manager.py to manager.pyc
byte-compiling build/bdist.linux-x86_64/egg/ansible/vars/reserved.pyto reserved.pyc
byte-compilingbuild/bdist.linux-x86_64/egg/ansible/vars/unsafe_proxy.py to unsafe_proxy.pyc
creatingbuild/bdist.linux-x86_64/egg/EGG-INFO
installing scripts tobuild/bdist.linux-x86_64/egg/EGG-INFO/scripts
running install_scripts
running build_scripts
creating build/scripts-2.7
copying and adjustingbin/ansible -> build/scripts-2.7
copying and adjustingbin/ansible-playbook -> build/scripts-2.7
copying and adjustingbin/ansible-pull -> build/scripts-2.7
copying and adjustingbin/ansible-doc -> build/scripts-2.7
copying and adjustingbin/ansible-galaxy -> build/scripts-2.7
copying and adjustingbin/ansible-console -> build/scripts-2.7
copying and adjustingbin/ansible-connection -> build/scripts-2.7
copying and adjustingbin/ansible-vault -> build/scripts-2.7
changing mode ofbuild/scripts-2.7/ansible from 644 to 755
changing mode ofbuild/scripts-2.7/ansible-playbook from 644 to 755
changing mode ofbuild/scripts-2.7/ansible-pull from 644 to 755
changing mode ofbuild/scripts-2.7/ansible-doc from 644 to 755
changing mode ofbuild/scripts-2.7/ansible-galaxy from 644 to 755
changing mode ofbuild/scripts-2.7/ansible-console from 644 to 755
changing mode ofbuild/scripts-2.7/ansible-connection from 644 to 755
changing mode ofbuild/scripts-2.7/ansible-vault from 644 to 755
creatingbuild/bdist.linux-x86_64/egg/EGG-INFO/scripts
copyingbuild/scripts-2.7/ansible -> build/bdist.linux-x86_64/egg/EGG-INFO/scripts
copyingbuild/scripts-2.7/ansible-connection ->build/bdist.linux-x86_64/egg/EGG-INFO/scripts
copyingbuild/scripts-2.7/ansible-config ->build/bdist.linux-x86_64/egg/EGG-INFO/scripts
copyingbuild/scripts-2.7/ansible-console ->build/bdist.linux-x86_64/egg/EGG-INFO/scripts
copying build/scripts-2.7/ansible-doc-> build/bdist.linux-x86_64/egg/EGG-INFO/scripts
copyingbuild/scripts-2.7/ansible-galaxy ->build/bdist.linux-x86_64/egg/EGG-INFO/scripts
copyingbuild/scripts-2.7/ansible-inventory ->build/bdist.linux-x86_64/egg/EGG-INFO/scripts
copyingbuild/scripts-2.7/ansible-playbook ->build/bdist.linux-x86_64/egg/EGG-INFO/scripts
copyingbuild/scripts-2.7/ansible-pull ->build/bdist.linux-x86_64/egg/EGG-INFO/scripts
copyingbuild/scripts-2.7/ansible-vault -> build/bdist.linux-x86_64/egg/EGG-INFO/scripts
changing mode ofbuild/bdist.linux-x86_64/egg/EGG-INFO/scripts/ansible to 755
changing mode ofbuild/bdist.linux-x86_64/egg/EGG-INFO/scripts/ansible-connection to 755
changing mode ofbuild/bdist.linux-x86_64/egg/EGG-INFO/scripts/ansible-config to 755
changing mode ofbuild/bdist.linux-x86_64/egg/EGG-INFO/scripts/ansible-console to 755
changing mode ofbuild/bdist.linux-x86_64/egg/EGG-INFO/scripts/ansible-doc to 755
changing mode ofbuild/bdist.linux-x86_64/egg/EGG-INFO/scripts/ansible-galaxy to 755
changing mode ofbuild/bdist.linux-x86_64/egg/EGG-INFO/scripts/ansible-inventory to 755
changing mode ofbuild/bdist.linux-x86_64/egg/EGG-INFO/scripts/ansible-playbook to 755
changing mode ofbuild/bdist.linux-x86_64/egg/EGG-INFO/scripts/ansible-pull to 755
changing mode ofbuild/bdist.linux-x86_64/egg/EGG-INFO/scripts/ansible-vault to 755
copyinglib/ansible.egg-info/PKG-INFO -> build/bdist.linux-x86_64/egg/EGG-INFO
copyinglib/ansible.egg-info/SOURCES.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copyinglib/ansible.egg-info/dependency_links.txt ->build/bdist.linux-x86_64/egg/EGG-INFO
copyinglib/ansible.egg-info/requires.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copyinglib/ansible.egg-info/top_level.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
zip_safe flag not set;analyzing archive contents...
ansible.cli.__init__: modulereferences __file__
ansible.cli.__init__: modulereferences __path__
ansible.config.manager: modulereferences __file__
ansible.executor.module_common:module references __file__
ansible.galaxy.__init__: modulereferences __file__
ansible.module_utils.basic:module references __file__
ansible.module_utils.gcp:module references __file__
ansible.module_utils.six.__init__:module references __path__
ansible.modules.cloud.amazon.ec2_elb_lb:module references __file__
ansible.modules.cloud.amazon.elb_classic_lb:module references __file__
ansible.modules.files.unarchive:module references __file__
ansible.modules.packaging.os.apt:module references __file__
ansible.modules.utilities.logic.async_wrapper:module references __file__
ansible.plugins.loader: modulereferences __file__
ansible.plugins.callback.__init__:module references __file__
ansible.plugins.callback.osx_say:module references __file__
creating dist
creating 'dist/ansible-2.4.3.0-py2.7.egg'and adding 'build/bdist.linux-x86_64/egg' to it
removing'build/bdist.linux-x86_64/egg' (and everything under it)
Processingansible-2.4.3.0-py2.7.egg
creating/usr/lib/python2.7/site-packages/ansible-2.4.3.0-py2.7.egg
Extracting ansible-2.4.3.0-py2.7.eggto /usr/lib/python2.7/site-packages
Adding ansible 2.4.3.0 toeasy-install.pth file
Installing ansible script to/usr/bin
Installing ansible-connectionscript to /usr/bin
Installing ansible-configscript to /usr/bin
Installing ansible-consolescript to /usr/bin
Installing ansible-doc scriptto /usr/bin
Installing ansible-galaxyscript to /usr/bin
Installing ansible-inventoryscript to /usr/bin
Installing ansible-playbookscript to /usr/bin
Installing ansible-pull scriptto /usr/bin
Installing ansible-vault scriptto /usr/bin
Installed/usr/lib/python2.7/site-packages/ansible-2.4.3.0-py2.7.egg
Processing dependencies foransible==2.4.3.0
Searching forsetuptools==36.5.0
Best match: setuptools 36.5.0
Processingsetuptools-36.5.0-py2.7.egg
setuptools 36.5.0 is alreadythe active version in easy-install.pth
Installing easy_install scriptto /usr/bin
Installing easy_install-2.7script to /usr/bin
Using/usr/lib/python2.7/site-packages/setuptools-36.5.0-py2.7.egg
Searching for cryptography==2.1.4
Best match: cryptography 2.1.4
Processingcryptography-2.1.4-py2.7-linux-x86_64.egg
cryptography 2.1.4 is alreadythe active version in easy-install.pth
Using/usr/lib64/python2.7/site-packages/cryptography-2.1.4-py2.7-linux-x86_64.egg
Searching for paramiko==2.3.0
Best match: paramiko 2.3.0
Processingparamiko-2.3.0-py2.7.egg
paramiko 2.3.0 is already theactive version in easy-install.pth
Using/usr/lib/python2.7/site-packages/paramiko-2.3.0-py2.7.egg
Searching for PyYAML==3.12
Best match: PyYAML 3.12
Adding PyYAML 3.12 toeasy-install.pth file
Using/usr/lib64/python2.7/site-packages
Searching for Jinja2==2.9.6
Best match: Jinja2 2.9.6
ProcessingJinja2-2.9.6-py2.7.egg
Jinja2 2.9.6 is already theactive version in easy-install.pth
Using /usr/lib/python2.7/site-packages/Jinja2-2.9.6-py2.7.egg
Searching for six==1.9.0
Best match: six 1.9.0
Adding six 1.9.0 toeasy-install.pth file
Using/usr/lib/python2.7/site-packages
Searching forasn1crypto==0.24.0
Best match: asn1crypto 0.24.0
Processingasn1crypto-0.24.0-py2.7.egg
asn1crypto 0.24.0 is alreadythe active version in easy-install.pth
Using/usr/lib/python2.7/site-packages/asn1crypto-0.24.0-py2.7.egg
Searching for idna==2.6
Best match: idna 2.6
Processing idna-2.6-py2.7.egg
idna 2.6 is already the activeversion in easy-install.pth
Using/usr/lib/python2.7/site-packages/idna-2.6-py2.7.egg
Searching for pyasn1==0.4.2
Best match: pyasn1 0.4.2
Processingpyasn1-0.4.2-py2.7.egg
pyasn1 0.4.2 is already theactive version in easy-install.pth
Using/usr/lib/python2.7/site-packages/pyasn1-0.4.2-py2.7.egg
Searching for PyNaCl==1.2.1
Best match: PyNaCl 1.2.1
ProcessingPyNaCl-1.2.1-py2.7-linux-x86_64.egg
PyNaCl 1.2.1 is already theactive version in easy-install.pth
Using /usr/lib64/python2.7/site-packages/PyNaCl-1.2.1-py2.7-linux-x86_64.egg
Searching for bcrypt==3.1.4
Best match: bcrypt 3.1.4
Processingbcrypt-3.1.4-py2.7-linux-x86_64.egg
bcrypt 3.1.4 is already theactive version in easy-install.pth
Using/usr/lib64/python2.7/site-packages/bcrypt-3.1.4-py2.7-linux-x86_64.egg
Searching for MarkupSafe==1.0
Best match: MarkupSafe 1.0
ProcessingMarkupSafe-1.0-py2.7-linux-x86_64.egg
MarkupSafe 1.0 is already theactive version in easy-install.pth
Using/usr/lib64/python2.7/site-packages/MarkupSafe-1.0-py2.7-linux-x86_64.egg
Searching for cffi==1.11.4
Best match: cffi 1.11.4
Processingcffi-1.11.4-py2.7-linux-x86_64.egg
cffi 1.11.4 is already theactive version in easy-install.pth
Using/usr/lib64/python2.7/site-packages/cffi-1.11.4-py2.7-linux-x86_64.egg
Searching for pycparser==2.18
Best match: pycparser 2.18
Adding pycparser 2.18 toeasy-install.pth file
Using/usr/lib/python2.7/site-packages
Finished processingdependencies for ansible==2.4.3.0
4 ansible配置
4.1 生成公钥/私钥
root@ansible01 bin]# ssh-keygen-t rsa -P ''
Generating public/private rsakey pair.
Enter file in which to save thekey (/root/.ssh/id_rsa):
Created directory '/root/.ssh'.
Your identification has beensaved in /root/.ssh/id_rsa.
Your public key has been savedin /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:22zbQPbSp26eaC+PYPocoHntNOc3Amgto+HM+FUZJ0sroot@ansible01
The key's randomart image is:
+---[RSA 2048]----+
| |
| |
| E . |
| . * |
| .oS o |
| .o=+o* o |
| =o+ooO.B o . |
| . =o * B+B++ |
| .. ..+.=XO. |
+----[SHA256]-----+
[root@ansible01 bin]# cat/root/.ssh/id_rsa.pub >>/root/.ssh/authorized_keys
[root@ansible01 bin]# chmod 600/root/.ssh/authorized_keys
写入信任文件(将/root/.ssh/id_rsa.pub分发到其他服务器,并在所有服务器上执行如下指令):
cat /root/.ssh/id_rsa.pub>>/root/.ssh/authorized_keys
chmod 600/root/.ssh/authorized_keys
4.2 配置
生成ansible配置文件
[root@ansible01ansible-2.4.3.0]# mkdir -p /etc/ansible
[root@ansible01ansible-2.4.3.0]# cp /opt/ansible/ansible-2.4.3.0/examples/ansible.cfg/etc/ansible/
配置文件/etc/ansible/hosts
vi /etc/ansible/hosts
[local]
127.0.0.1
[target]
192.168.2.20
192.168.2.30
5 测试
ping模块测试
[root@ansible01ansible-2.4.3.0]# ansible all -m ping --ask-pass
SSH password:
192.168.2.20 | SUCCESS => {
"changed": false,
"ping": "pong"
}
127.0.0.1 | SUCCESS => {
"changed": false,
"ping": "pong"
}
192.168.2.30 | SUCCESS => {
"changed": false,
"ping": "pong"
}
[root@ansible01ansible-2.4.3.0]#
command模块测试
[root@ansible01ansible-2.4.3.0]# ansible target -m command -a'uptime'
192.168.2.30 | SUCCESS | rc=0>>
10:17:34 up 1:00, 2 users, load average: 0.03, 0.02, 0.05
192.168.2.20 | SUCCESS | rc=0>>
10:17:34 up 1:01, 2 users, load average: 0.12, 0.09, 0.06
[root@ansible01ansible-2.4.3.0]#
用户模块测试
[root@ansible01ansible-2.4.3.0]# ansible target -m user -a "name=cdscomment='hello,cds'"
192.168.2.30 | SUCCESS => {
"append": false,
"changed": false,
"comment": "hello,cds",
"group": 1001,
"home": "/home/cds",
"move_home": false,
"name": "cds",
"shell": "/bin/bash",
"state": "present",
"uid": 1001
}
192.168.2.20 | SUCCESS => {
"changed": true,
"comment": "hello,cds",
"createhome": true,
"group": 1001,
"home": "/home/cds",
"name": "cds",
"shell": "/bin/bash",
"state": "present",
"system": false,
"uid": 1001
}
评论暂时关闭