您的位置:首页 > 运维架构 > Linux

redhat7.4+ansible2.4.3.0离线安装指南

2018-02-28 10:51 676 查看
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.0asn1crypto-0.24.0bcrypt-3.1.4cffi-1.11.4cryptography-2.0.3ecdsa-0.13enum34-1.1.6idna-2.6ipaddress-1.0.19Jinja2-2.9.6markupsafe-masterparamiko-2.3.0pyasn1-0.4.2pycparser-2.18pycrypto-2.6.1PyNaCl-1.2.1PyYAML-3.12setuptools-36.5.0simplejson-3.13.2sshpass-1.06yaml-0.1.7操作系统需要安装的rpm包主要有以下几个,建议采用yum安装:gccpython-developenssl-devellibffi-develzlib-devellibyaml

3        ansible及相关包安装

3.1 离线文件上传

将所有以下安装包上传到/opt/ansible目录下。ansible-2.4.3.0.tar.gzasn1crypto-0.24.0.tar.gzbcrypt-3.1.4.tar.gzcffi-1.11.4.tar.gzcryptography-2.0.3.tar.gzecdsa-0.13.tar.gzenum34-1.1.6.tar.gzidna-2.6.tar.gzipaddress-1.0.19.tar.gzJinja2-2.9.6.tar.gzmarkupsafe-master.zipparamiko-2.3.0.tar.gzpyasn1-0.4.2.tar.gzpycparser-2.18.tar.gzpycrypto-2.6.1.tar.gzPyNaCl-1.2.1.tar.gzPyYAML-3.12.tar.gzsetuptools-36.5.0.zipsimplejson-3.13.2.tar.gzsshpass-1.06.tar.gzyaml-0.1.7.tar.gz

3.2 依赖包安装

setuptools
cd /opt/ansibleunzip setuptools-36.5.0.zipcd setuptools-36.5.0python setup.py installpycrypto
cd /opt/ansibletar -xzvf pycrypto-2.6.1.tar.gzcd pycrypto-2.6.1python setup.py installyaml
cd /opt/ansibletar -xzvf yaml-0.1.7.tar.gz cd yaml-0.1.7./configuremake --jobs=`grep processor/proc/cpuinfo | wc -l`make installPyYAML
cd /opt/ansibletar -xzvf PyYAML-3.12.tar.gzcd PyYAML-3.12python setup.py installMarkupSafe
cd /opt/ansibleunzip markupsafe-master.zipcd markupsafe-masterpython setup.py installecdsa
cd /opt/ansibletar -xzvf ecdsa-0.13.tar.gzcd ecdsa-0.13python setup.py installpyasn1
cd /opt/ansibletar -xzvf pyasn1-0.4.2.tar.gz cd pyasn1-0.4.2python setup.py installpycparser
cd /opt/ansibletar -xzvf pycparser-2.18.tar.gzcd pycparser-2.18python setup.py installcffi
cd /opt/ansibletar -xzvf cffi-1.11.4.tar.gzcd cffi-1.11.4python setup.py installPyNaCl
cd /opt/ansibletar -xzvf PyNaCl-1.2.1.tar.gz cd PyNaCl-1.2.1python setup.py installipaddress
cd /opt/ansibletar -xzvfipaddress-1.0.19.tar.gzcd ipaddress-1.0.19python setup.py installenum34
cd /opt/ansibletar -xzvf enum34-1.1.6.tar.gzcd enum34-1.1.6python setup.py installasn1crypto
cd /opt/ansibletar -xzvfasn1crypto-0.24.0.tar.gzcd asn1crypto-0.24.0python setup.py installidna
cd /opt/ansibletar -xzvf idna-2.6.tar.gzcd idna-2.6python setup.py installcryptography
cd /opt/ansibletar -xzvfcryptography-2.0.3.tar.gzcd cryptography-2.0.3python setup.py installbcrypt
cd /opt/ansibletar -xzvf bcrypt-3.1.4.tar.gzcd bcrypt-3.1.4python setup.py installparamiko
cd /opt/ansibletar -xzvf paramiko-2.3.0.tar.gzcd paramiko-2.3.0python setup.py installsimplejson
cd /opt/ansibletar -xzvf simplejson-3.13.2.tar.gzcd simplejson-3.13.2python setup.py install

3.3 安装ansible

cd /opt/ansibletar -xzvf ansible-2.4.3.0.tar.gzcd ansible-2.4.3.0python setup.py install ...byte-compilingbuild/bdist.linux-x86_64/egg/ansible/utils/module_docs_fragments/oneview.py tooneview.pycbyte-compiling build/bdist.linux-x86_64/egg/ansible/utils/module_docs_fragments/openstack.pyto openstack.pycbyte-compilingbuild/bdist.linux-x86_64/egg/ansible/utils/module_docs_fragments/openswitch.pyto openswitch.pycbyte-compilingbuild/bdist.linux-x86_64/egg/ansible/utils/module_docs_fragments/ovirt.py toovirt.pycbyte-compilingbuild/bdist.linux-x86_64/egg/ansible/utils/module_docs_fragments/ovirt_facts.pyto ovirt_facts.pycbyte-compilingbuild/bdist.linux-x86_64/egg/ansible/utils/module_docs_fragments/postgres.py topostgres.pycbyte-compilingbuild/bdist.linux-x86_64/egg/ansible/utils/module_docs_fragments/purestorage.pyto purestorage.pycbyte-compilingbuild/bdist.linux-x86_64/egg/ansible/utils/module_docs_fragments/rackspace.pyto rackspace.pycbyte-compiling build/bdist.linux-x86_64/egg/ansible/utils/module_docs_fragments/return_common.pyto return_common.pycbyte-compilingbuild/bdist.linux-x86_64/egg/ansible/utils/module_docs_fragments/sros.py tosros.pycbyte-compiling build/bdist.linux-x86_64/egg/ansible/utils/module_docs_fragments/tower.pyto tower.pycbyte-compilingbuild/bdist.linux-x86_64/egg/ansible/utils/module_docs_fragments/validate.py tovalidate.pycbyte-compilingbuild/bdist.linux-x86_64/egg/ansible/utils/module_docs_fragments/vca.py tovca.pycbyte-compilingbuild/bdist.linux-x86_64/egg/ansible/utils/module_docs_fragments/vmware.py tovmware.pycbyte-compilingbuild/bdist.linux-x86_64/egg/ansible/utils/module_docs_fragments/vyos.py tovyos.pycbyte-compiling build/bdist.linux-x86_64/egg/ansible/vars/__init__.pyto __init__.pycbyte-compilingbuild/bdist.linux-x86_64/egg/ansible/vars/hostvars.py to hostvars.pycbyte-compilingbuild/bdist.linux-x86_64/egg/ansible/vars/manager.py to manager.pycbyte-compiling build/bdist.linux-x86_64/egg/ansible/vars/reserved.pyto reserved.pycbyte-compilingbuild/bdist.linux-x86_64/egg/ansible/vars/unsafe_proxy.py to unsafe_proxy.pyccreatingbuild/bdist.linux-x86_64/egg/EGG-INFOinstalling scripts tobuild/bdist.linux-x86_64/egg/EGG-INFO/scriptsrunning install_scriptsrunning build_scriptscreating build/scripts-2.7copying and adjustingbin/ansible -> build/scripts-2.7copying and adjustingbin/ansible-playbook -> build/scripts-2.7copying and adjustingbin/ansible-pull -> build/scripts-2.7copying and adjustingbin/ansible-doc -> build/scripts-2.7copying and adjustingbin/ansible-galaxy -> build/scripts-2.7copying and adjustingbin/ansible-console -> build/scripts-2.7copying and adjustingbin/ansible-connection -> build/scripts-2.7copying and adjustingbin/ansible-vault -> build/scripts-2.7changing mode ofbuild/scripts-2.7/ansible from 644 to 755changing mode ofbuild/scripts-2.7/ansible-playbook from 644 to 755changing mode ofbuild/scripts-2.7/ansible-pull from 644 to 755changing mode ofbuild/scripts-2.7/ansible-doc from 644 to 755changing mode ofbuild/scripts-2.7/ansible-galaxy from 644 to 755changing mode ofbuild/scripts-2.7/ansible-console from 644 to 755changing mode ofbuild/scripts-2.7/ansible-connection from 644 to 755changing mode ofbuild/scripts-2.7/ansible-vault from 644 to 755creatingbuild/bdist.linux-x86_64/egg/EGG-INFO/scriptscopyingbuild/scripts-2.7/ansible -> build/bdist.linux-x86_64/egg/EGG-INFO/scriptscopyingbuild/scripts-2.7/ansible-connection ->build/bdist.linux-x86_64/egg/EGG-INFO/scriptscopyingbuild/scripts-2.7/ansible-config ->build/bdist.linux-x86_64/egg/EGG-INFO/scriptscopyingbuild/scripts-2.7/ansible-console ->build/bdist.linux-x86_64/egg/EGG-INFO/scriptscopying build/scripts-2.7/ansible-doc-> build/bdist.linux-x86_64/egg/EGG-INFO/scriptscopyingbuild/scripts-2.7/ansible-galaxy ->build/bdist.linux-x86_64/egg/EGG-INFO/scriptscopyingbuild/scripts-2.7/ansible-inventory ->build/bdist.linux-x86_64/egg/EGG-INFO/scriptscopyingbuild/scripts-2.7/ansible-playbook ->build/bdist.linux-x86_64/egg/EGG-INFO/scriptscopyingbuild/scripts-2.7/ansible-pull ->build/bdist.linux-x86_64/egg/EGG-INFO/scriptscopyingbuild/scripts-2.7/ansible-vault -> build/bdist.linux-x86_64/egg/EGG-INFO/scriptschanging mode ofbuild/bdist.linux-x86_64/egg/EGG-INFO/scripts/ansible to 755changing mode ofbuild/bdist.linux-x86_64/egg/EGG-INFO/scripts/ansible-connection to 755changing mode ofbuild/bdist.linux-x86_64/egg/EGG-INFO/scripts/ansible-config to 755changing mode ofbuild/bdist.linux-x86_64/egg/EGG-INFO/scripts/ansible-console to 755changing mode ofbuild/bdist.linux-x86_64/egg/EGG-INFO/scripts/ansible-doc to 755changing mode ofbuild/bdist.linux-x86_64/egg/EGG-INFO/scripts/ansible-galaxy to 755changing mode ofbuild/bdist.linux-x86_64/egg/EGG-INFO/scripts/ansible-inventory to 755changing mode ofbuild/bdist.linux-x86_64/egg/EGG-INFO/scripts/ansible-playbook to 755changing mode ofbuild/bdist.linux-x86_64/egg/EGG-INFO/scripts/ansible-pull to 755changing mode ofbuild/bdist.linux-x86_64/egg/EGG-INFO/scripts/ansible-vault to 755copyinglib/ansible.egg-info/PKG-INFO -> build/bdist.linux-x86_64/egg/EGG-INFOcopyinglib/ansible.egg-info/SOURCES.txt -> build/bdist.linux-x86_64/egg/EGG-INFOcopyinglib/ansible.egg-info/dependency_links.txt ->build/bdist.linux-x86_64/egg/EGG-INFOcopyinglib/ansible.egg-info/requires.txt -> build/bdist.linux-x86_64/egg/EGG-INFOcopyinglib/ansible.egg-info/top_level.txt -> build/bdist.linux-x86_64/egg/EGG-INFOzip_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 distcreating 'dist/ansible-2.4.3.0-py2.7.egg'and adding 'build/bdist.linux-x86_64/egg' to itremoving'build/bdist.linux-x86_64/egg' (and everything under it)Processingansible-2.4.3.0-py2.7.eggcreating/usr/lib/python2.7/site-packages/ansible-2.4.3.0-py2.7.eggExtracting ansible-2.4.3.0-py2.7.eggto /usr/lib/python2.7/site-packagesAdding ansible 2.4.3.0 toeasy-install.pth fileInstalling ansible script to/usr/binInstalling ansible-connectionscript to /usr/binInstalling ansible-configscript to /usr/binInstalling ansible-consolescript to /usr/binInstalling ansible-doc scriptto /usr/binInstalling ansible-galaxyscript to /usr/binInstalling ansible-inventoryscript to /usr/binInstalling ansible-playbookscript to /usr/binInstalling ansible-pull scriptto /usr/binInstalling ansible-vault scriptto /usr/bin Installed/usr/lib/python2.7/site-packages/ansible-2.4.3.0-py2.7.eggProcessing dependencies foransible==2.4.3.0Searching forsetuptools==36.5.0Best match: setuptools 36.5.0Processingsetuptools-36.5.0-py2.7.eggsetuptools 36.5.0 is alreadythe active version in easy-install.pthInstalling easy_install scriptto /usr/binInstalling easy_install-2.7script to /usr/bin Using/usr/lib/python2.7/site-packages/setuptools-36.5.0-py2.7.eggSearching for cryptography==2.1.4Best match: cryptography 2.1.4Processingcryptography-2.1.4-py2.7-linux-x86_64.eggcryptography 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.eggSearching for paramiko==2.3.0Best match: paramiko 2.3.0Processingparamiko-2.3.0-py2.7.eggparamiko 2.3.0 is already theactive version in easy-install.pth Using/usr/lib/python2.7/site-packages/paramiko-2.3.0-py2.7.eggSearching for PyYAML==3.12Best match: PyYAML 3.12Adding PyYAML 3.12 toeasy-install.pth file Using/usr/lib64/python2.7/site-packagesSearching for Jinja2==2.9.6Best match: Jinja2 2.9.6ProcessingJinja2-2.9.6-py2.7.eggJinja2 2.9.6 is already theactive version in easy-install.pth Using /usr/lib/python2.7/site-packages/Jinja2-2.9.6-py2.7.eggSearching for six==1.9.0Best match: six 1.9.0Adding six 1.9.0 toeasy-install.pth file Using/usr/lib/python2.7/site-packagesSearching forasn1crypto==0.24.0Best match: asn1crypto 0.24.0Processingasn1crypto-0.24.0-py2.7.eggasn1crypto 0.24.0 is alreadythe active version in easy-install.pth Using/usr/lib/python2.7/site-packages/asn1crypto-0.24.0-py2.7.eggSearching for idna==2.6Best match: idna 2.6Processing idna-2.6-py2.7.eggidna 2.6 is already the activeversion in easy-install.pth Using/usr/lib/python2.7/site-packages/idna-2.6-py2.7.eggSearching for pyasn1==0.4.2Best match: pyasn1 0.4.2Processingpyasn1-0.4.2-py2.7.eggpyasn1 0.4.2 is already theactive version in easy-install.pth Using/usr/lib/python2.7/site-packages/pyasn1-0.4.2-py2.7.eggSearching for PyNaCl==1.2.1Best match: PyNaCl 1.2.1ProcessingPyNaCl-1.2.1-py2.7-linux-x86_64.eggPyNaCl 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.eggSearching for bcrypt==3.1.4Best match: bcrypt 3.1.4Processingbcrypt-3.1.4-py2.7-linux-x86_64.eggbcrypt 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.eggSearching for MarkupSafe==1.0Best match: MarkupSafe 1.0ProcessingMarkupSafe-1.0-py2.7-linux-x86_64.eggMarkupSafe 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.eggSearching for cffi==1.11.4Best match: cffi 1.11.4Processingcffi-1.11.4-py2.7-linux-x86_64.eggcffi 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.eggSearching for pycparser==2.18Best match: pycparser 2.18Adding pycparser 2.18 toeasy-install.pth file Using/usr/lib/python2.7/site-packagesFinished 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@ansible01The 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_keyschmod 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.20192.168.2.30

5        测试

ping模块测试
[root@ansible01ansible-2.4.3.0]# ansible all -m ping --ask-passSSH 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.05192.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}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Linux ansible 离线安装