在CentOS 7.3 上安装Ansible,centosansible


CentOS 7.3 默认已经安装了python2.7版本。

如果你不想用root来安装Ansible,则可以将Ansible安全地安装到一个Python virtualenv中。如果你对Python virtualenv不熟悉,可以使用一个比较新的工具pipsi,它可以帮你自动将Ansbile安装到Python virtualenv中:

获取pipsi安装包

[rems2@rems2 ~]$ wget https://raw.githubusercontent.com/mitsuhiko/pipsi/master/get-pipsi.py
--2017-07-27 10:37:23--  https://raw.githubusercontent.com/mitsuhiko/pipsi/master/get-pipsi.py
Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 151.101.72.133
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|151.101.72.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 4130 (4.0K) [text/plain]
Saving to: ‘get-pipsi.py100%[==================================================================================================================>] 4,130       --.-K/s   in 0s

2017-07-27 10:37:24 (59.4 MB/s) - ‘get-pipsi.py’ saved [4130/4130]

用root用户安装virtualenv

[root@rems2 ~]# easy_install virtualenv
Searching for virtualenv
Reading https://pypi.python.org/simple/virtualenv/
Best match: virtualenv 15.1.0
Downloading https://pypi.python.org/packages/d4/0c/9840c08189e030873387a73b90ada981885010dd9aea134d6de30cd24cb8/virtualenv-15.1.0.tar.gz#md5=44e19f4134906fe2d75124427dc9b716
Processing virtualenv-15.1.0.tar.gz
Writing /tmp/easy_install-NAybb6/virtualenv-15.1.0/setup.cfg
Running virtualenv-15.1.0/setup.py -q bdist_egg --dist-dir /tmp/easy_install-NAybb6/virtualenv-15.1.0/egg-dist-tmp-XQQxfR
warning: no previously-included files matching '*' found under directory 'docs/_templates'
warning: no previously-included files matching '*' found under directory 'docs/_build'
Adding virtualenv 15.1.0 to easy-install.pth file
Installing virtualenv script to /usr/bin

Installed /usr/lib/python2.7/site-packages/virtualenv-15.1.0-py2.7.egg
Processing dependencies for virtualenv
Finished processing dependencies for virtualenv

普通用户安装会报错。如:

[rems2@rems2 ~]$ easy_install virtualenv
error: can't create or remove files in install directory

The following error occurred while trying to add or remove files in the
installation directory:

    [Errno 13] Permission denied: '/usr/lib/python2.7/site-packages/test-easy-install-2870.write-test'

The installation directory you specified (via --install-dir, --prefix, or
the distutils default setting) was:

    /usr/lib/python2.7/site-packages/

Perhaps your account does not have write access to this directory?  If the
installation directory is a system-owned directory, you may need to sign in
as the administrator or "root" account.  If you do not have administrative
access to this machine, you may wish to choose a different installation
directory, preferably one that is listed in your PYTHONPATH environment
variable.

For information on other options, you may wish to consult the
documentation at:

  https://pythonhosted.org/setuptools/easy_install.html

Please make the appropriate changes for your system and try again.

安装pipsi工具

[rems2@rems2 ~]$ python get-pipsi.py
Installing pipsi
New python executable in /home/rems2/.local/venvs/pipsi/bin/python
Installing setuptools, pip, wheel...done.
Collecting pipsi
  Downloading pipsi-0.9-py2-none-any.whl
Collecting Click (from pipsi)
  Downloading click-6.7-py2.py3-none-any.whl (71kB)
    100% |████████████████████████████████| 71kB 258kB/s
Collecting virtualenv (from pipsi)
  Downloading virtualenv-15.1.0-py2.py3-none-any.whl (1.8MB)
    100% |████████████████████████████████| 1.8MB 144kB/s
Installing collected packages: Click, virtualenv, pipsi
Successfully installed Click-6.7 pipsi-0.9 virtualenv-15.1.0
Installed pipsi binary in /home/rems2/.local/bin
pipsi is now installed.

安装2个必要的rpm包

yum install gcc
yum install python-devel

用pipsi工具安装Ansible

[rems2@rems2 ~]$ python get-pipsi.py
Installing pipsi
New python executable in /home/rems2/.local/venvs/pipsi/bin/python
Installing setuptools, pip, wheel...done.
Collecting pipsi
  Downloading pipsi-0.9-py2-none-any.whl
Collecting Click (from pipsi)
  Downloading click-6.7-py2.py3-none-any.whl (71kB)
    100% |████████████████████████████████| 71kB 253kB/s
Collecting virtualenv (from pipsi)
  Downloading virtualenv-15.1.0-py2.py3-none-any.whl (1.8MB)
    100% |████████████████████████████████| 1.8MB 372kB/s
Installing collected packages: Click, virtualenv, pipsi
Successfully installed Click-6.7 pipsi-0.9 virtualenv-15.1.0
Installed pipsi binary in /home/rems2/.local/bin
pipsi is now installed.
[rems2@rems2 ~]$ pipsi  install ansible
Running virtualenv with interpreter /home/rems2/.local/venvs/pipsi/bin/python
Using real prefix '/usr'
New python executable in /home/rems2/.local/venvs/ansible/bin/python
Installing setuptools, pip, wheel...done.
Collecting ansible
  Downloading ansible-2.3.1.0.tar.gz (4.3MB)
    100% |████████████████████████████████| 4.3MB 194kB/s
Collecting jinja2 (from ansible)
  Downloading Jinja2-2.9.6-py2.py3-none-any.whl (340kB)
    100% |████████████████████████████████| 348kB 457kB/s
Collecting PyYAML (from ansible)
  Downloading PyYAML-3.12.tar.gz (253kB)
    100% |████████████████████████████████| 256kB 302kB/s
Collecting paramiko (from ansible)
  Downloading paramiko-2.2.1-py2.py3-none-any.whl (176kB)
    100% |████████████████████████████████| 184kB 159kB/s
Collecting pycrypto>=2.6 (from ansible)
  Downloading pycrypto-2.6.1.tar.gz (446kB)
    100% |████████████████████████████████| 450kB 311kB/s
Requirement already satisfied: setuptools in ./.local/venvs/ansible/lib/python2.7/site-packages (from ansible)
Collecting MarkupSafe>=0.23 (from jinja2->ansible)
  Downloading MarkupSafe-1.0.tar.gz
Collecting cryptography>=1.1 (from paramiko->ansible)
  Downloading cryptography-2.0.2-cp27-cp27mu-manylinux1_x86_64.whl (2.2MB)
    100% |████████████████████████████████| 2.2MB 201kB/s
Collecting bcrypt>=3.1.3 (from paramiko->ansible)
  Downloading bcrypt-3.1.3-cp27-cp27mu-manylinux1_x86_64.whl (57kB)
    100% |████████████████████████████████| 61kB 286kB/s
Collecting pyasn1>=0.1.7 (from paramiko->ansible)
  Downloading pyasn1-0.3.1-py2.py3-none-any.whl (61kB)
    100% |████████████████████████████████| 71kB 363kB/s
Collecting pynacl>=1.0.1 (from paramiko->ansible)
  Downloading PyNaCl-1.1.2-cp27-cp27mu-manylinux1_x86_64.whl (539kB)
    100% |████████████████████████████████| 542kB 258kB/s
Collecting idna>=2.1 (from cryptography>=1.1->paramiko->ansible)
  Downloading idna-2.5-py2.py3-none-any.whl (55kB)
    100% |████████████████████████████████| 61kB 300kB/s
Collecting six>=1.4.1 (from cryptography>=1.1->paramiko->ansible)
  Downloading six-1.10.0-py2.py3-none-any.whl
Collecting ipaddress (from cryptography>=1.1->paramiko->ansible)
  Downloading ipaddress-1.0.18-py2-none-any.whl
Collecting asn1crypto>=0.21.0 (from cryptography>=1.1->paramiko->ansible)
  Downloading asn1crypto-0.22.0-py2.py3-none-any.whl (97kB)
    100% |████████████████████████████████| 102kB 244kB/s
Collecting enum34 (from cryptography>=1.1->paramiko->ansible)
  Downloading enum34-1.1.6-py2-none-any.whl
Collecting cffi>=1.7 (from cryptography>=1.1->paramiko->ansible)
  Downloading cffi-1.10.0-cp27-cp27mu-manylinux1_x86_64.whl (392kB)
    100% |████████████████████████████████| 399kB 191kB/s
Collecting pycparser (from cffi>=1.7->cryptography>=1.1->paramiko->ansible)
  Downloading pycparser-2.18.tar.gz (245kB)
    100% |████████████████████████████████| 256kB 171kB/s
Building wheels for collected packages: ansible, PyYAML, pycrypto, MarkupSafe, pycparser
  Running setup.py bdist_wheel for ansible ... done
  Stored in directory: /home/rems2/.cache/pip/wheels/db/42/8c/a00fdd1e70acccc3f3b27eb4265cbfcccb5f6a52a4b9195403
  Running setup.py bdist_wheel for PyYAML ... done
  Stored in directory: /home/rems2/.cache/pip/wheels/2c/f7/79/13f3a12cd723892437c0cfbde1230ab4d82947ff7b3839a4fc
  Running setup.py bdist_wheel for pycrypto ... done
  Stored in directory: /home/rems2/.cache/pip/wheels/80/1f/94/f76e9746864f198eb0e304aeec319159fa41b082f61281ffce
  Running setup.py bdist_wheel for MarkupSafe ... done
  Stored in directory: /home/rems2/.cache/pip/wheels/88/a7/30/e39a54a87bcbe25308fa3ca64e8ddc75d9b3e5afa21ee32d57
  Running setup.py bdist_wheel for pycparser ... done
  Stored in directory: /home/rems2/.cache/pip/wheels/95/14/9a/5e7b9024459d2a6600aaa64e0ba485325aff7a9ac7489db1b6
Successfully built ansible PyYAML pycrypto MarkupSafe pycparser
Installing collected packages: MarkupSafe, jinja2, PyYAML, idna, six, ipaddress, asn1crypto, enum34, pycparser, cffi, cryptography, bcrypt, pyasn1, pynacl, paramiko, pycrypto, ansible
Successfully installed MarkupSafe-1.0 PyYAML-3.12 ansible-2.3.1.0 asn1crypto-0.22.0 bcrypt-3.1.3 cffi-1.10.0 cryptography-2.0.2 enum34-1.1.6 idna-2.5 ipaddress-1.0.18 jinja2-2.9.6 paramiko-2.2.1 pyasn1-0.3.1 pycparser-2.18 pycrypto-2.6.1 pynacl-1.1.2 six-1.10.0
  Linked script /home/rems2/.local/bin/ansible
  Linked script /home/rems2/.local/bin/ansible-connection
  Linked script /home/rems2/.local/bin/ansible-console
  Linked script /home/rems2/.local/bin/ansible-doc
  Linked script /home/rems2/.local/bin/ansible-galaxy
  Linked script /home/rems2/.local/bin/ansible-playbook
  Linked script /home/rems2/.local/bin/ansible-pull
  Linked script /home/rems2/.local/bin/ansible-vault
Done.

相关内容

    暂无相关文章