目标:在RedHat Linux计算机上安装ansible。
关于如何开始的概述: 当我的Linux机器是RedHat 5.9(Tikanga)时,默认的python安装版本是2.4。我尽我所能,但无法得到任何工作,因为Ansible需要python> = 2.6。我尝试在Linux 5.9版本上安装2.7.9,但事情开始变得非常快。
我在Linux 5.9上尝试使用2.7.9 python作为“make altinstall”而不是安装但是在运行yum / etc系统级命令时仍然存在很多错误。
很少有错误(有或没有运行sudo):
#sudo pip install ansible
Traceback (most recent call last):
File "/usr/bin/pip", line 7, in ?
sys.exit(
File "/usr/lib/python2.4/site-packages/pkg_resources.py", line 236, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/usr/lib/python2.4/site-packages/pkg_resources.py", line 2097, in load_entry_point
return ep.load()
File "/usr/lib/python2.4/site-packages/pkg_resources.py", line 1830, in load
entry = __import__(self.module_name, globals(),globals(), ['__name__'])
File "/usr/lib/python2.4/site-packages/pip-6.0.8-py2.4.egg/pip/__init__.py", line 211
except PipError as exc:
^
SyntaxError: invalid syntax
或
#sudo easy_install pip
Searching for pip
Best match: pip 6.0.8
Processing pip-6.0.8-py2.4.egg
pip 6.0.8 is already the active version in easy-install.pth
Installing pip script to /usr/bin
Installing pip2 script to /usr/bin
Installing pip2.4 script to /usr/bin
Using /usr/lib/python2.4/site-packages/pip-6.0.8-py2.4.egg
Processing dependencies for pip
或
#sudo pip install ansible
Traceback (most recent call last):
File "/usr/bin/pip", line 7, in ?
sys.exit(
File "/usr/lib/python2.4/site-packages/pkg_resources.py", line 236, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/usr/lib/python2.4/site-packages/pkg_resources.py", line 2097, in load_entry_point
return ep.load()
File "/usr/lib/python2.4/site-packages/pkg_resources.py", line 1830, in load
entry = __import__(self.module_name, globals(),globals(), ['__name__'])
File "/usr/lib/python2.4/site-packages/pip-6.0.8-py2.4.egg/pip/__init__.py", line 211
except PipError as exc:
^
SyntaxError: invalid syntax
或
#sudo easy_install ansible
'import site' failed; use -v for traceback
Traceback (most recent call last):
File "/usr/bin/easy_install", line 5, in ?
from pkg_resources import load_entry_point
ImportError: No module named pkg_resources
等...
最后,为了我的运气,我想,让我们尝试从头开始再次安装python(所以我跑 yum erase python ,!!!小心!!!!)据我所知,这是最好的命令我曾经根据我的经验进行过一次疏忽。最终结果:我最终在这里创建了一个新产品:http://www.keepcalmandcarryon.com/creator/?shortcode=qCsMlpyc
无论如何,...现在,我使用较新版本的RedHat(版本6.6 Santiago)恢复了服务器,这次默认Python就是:2.6.6。
目前的情况:现在,我现在正在安装Python 2.6.6的RH Linux 5.9上面对。
我正在投放: sudo easy_install pip ,但我收到了错误消息:
sudo: easy_install: command not found
要解决上述问题,我现在正在运行:sudo yum install python-setuptools
它发现了......但是给我一些错误。
Loaded plugins: product-id, security, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Setting up Install Process
http://74.125.194.100/yum/x86_64/6Server/%24YUM0/Server/repodata/repomd.xml: [Errno 14] PYCURL ERROR 22 - "The requested URL returned error: 404 Not Found"
Trying other mirror.
http://74.125.194.100/yum/x86_64/supplemental/%24YUM0/repodata/repomd.xml: [Errno 14] PYCURL ERROR 22 - "The requested URL returned error: 404 Not Found"
Trying other mirror.
Resolving Dependencies
--> Running transaction check
---> Package python-setuptools.noarch 0:0.6.10-3.el6 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
==============================================================================================================================================================================================================================
Package Arch Version Repository Size
==============================================================================================================================================================================================================================
Installing:
python-setuptools noarch 0.6.10-3.el6 release.update 336 k
Transaction Summary
==============================================================================================================================================================================================================================
Install 1 Package(s)
Total download size: 336 k
Installed size: 1.5 M
Is this ok [y/N]: y
Downloading Packages:
http://74.125.194.100/yum/x86_64/6Server/%24YUM0/Server/../Packages/python-setuptools-0.6.10-3.el6.noarch.rpm: [Errno 14] PYCURL ERROR 22 - "The requested URL returned error: 404 Not Found"
Trying other mirror.
Error Downloading Packages:
python-setuptools-0.6.10-3.el6.noarch: failure: ../Packages/python-setuptools-0.6.10-3.el6.noarch.rpm from release.update: [Errno 256] No more mirrors to try.
-bash-4.1$
任何想法,如何在我的Linux机器6.6(现在)上获得easy_install,pip或ansible。
感谢。
答案 0 :(得分:1)
使用以下命令修复所有内容,现在最终安装了ansible:
wget http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
sudo rpm -ivh epel-release-6-8.noarch.rpm
但是在这个阶段,我得到了Jinja2的错误......如下所示: ImportError:没有名为setuptools的模块
-bash-4.1$ sudo python setup.py install
Traceback (most recent call last):
File "setup.py", line 40, in <module>
from setuptools import setup, Extension, Feature
ImportError: No module named setuptools
-bash-4.1$
要解决上述问题并继续,我运行以下命令以获取python-setuptools(安装easy_install)
wget https://bootstrap.pypa.io/ez_setup.py -O - | sudo python
很好,现在我已经在我的机器上安装了easy_install。
-bash-4.1$ which easy_install
/usr/bin/easy_install
-bash-4.1$
此时,我想安装ANSIBLE,所以我运行了以下内容:
sudo easy_install pip
sudo pip install ansible
上面的ansible install命令输出的最后一行是:
Successfully installed ansible-1.9.0.1 jinja2-2.7.3 markupsafe-0.23 pycrypto-2.6.1
现在,我可以在我的机器上看到ansible。
-bash-4.1$ which ansible
/usr/bin/ansible
-bash-4.1$
哦,哦......有些事情还不好:
-bash-4.1 $ ansible --help
Traceback (most recent call last):
File "/usr/bin/ansible", line 36, in <module>
from ansible.runner import Runner
File "/usr/lib/python2.6/site-packages/ansible/runner/__init__.py", line 62, in <module>
from Crypto.Random import atfork
File "/usr/lib64/python2.6/site-packages/Crypto/Random/__init__.py", line 29, in <module>
from Crypto.Random import _UserFriendlyRNG
File "/usr/lib64/python2.6/site-packages/Crypto/Random/_UserFriendlyRNG.py", line 38, in <module>
from Crypto.Random.Fortuna import FortunaAccumulator
File "/usr/lib64/python2.6/site-packages/Crypto/Random/Fortuna/FortunaAccumulator.py", line 39, in <module>
import FortunaGenerator
File "/usr/lib64/python2.6/site-packages/Crypto/Random/Fortuna/FortunaGenerator.py", line 34, in <module>
from Crypto.Util.number import ceil_shift, exact_log2, exact_div
File "/usr/lib64/python2.6/site-packages/Crypto/Util/number.py", line 56, in <module>
if _fastmath is not None and not _fastmath.HAVE_DECL_MPZ_POWM_SEC:
AttributeError: 'module' object has no attribute 'HAVE_DECL_MPZ_POWM_SEC'
<强> -bash-4.1 $ 强>
我检查过,我的LD_LIBRARY_PATH变量已经设置/导出为:
LD_LIBRARY_PATH=/usr/lib64/:/usr/local/lib64
然后还有什么......好的。
执行以下步骤/命令以解决上述错误并获得实际工作的问题!!!对于提示,我说是“是”。
echo "y" | sudo pip uninstall pycrypto
echo "y" | sudo yum erase python-crypto
echo "y" | sudo pip uninstall ansible
sudo pip install ansible
## Time to get gmplib 6.0.0(a) etc
wget https://gmplib.org/download/gmp/gmp-6.0.0a.tar.bz2
tar -xvjpf gmp-6.0.0a.tar.bz2
## Change to the above extracted folder and run some commands, seems like they'll run forever.
cd gmp-6.0.0
./configure
sudo make || echo "these few steps will take good amt of time to complete"
sudo make check || echo "hang on and see if all tests passes in the check process"
sudo make install || echo "final shenzi will be done shortly"
sudo make check || echo "really!!!! ????"
which ansible
ansible || ansible --help
<强> !!!最后!!! ----
-bash-4.1 $,其中ansible
/usr/bin/ansible
-bash-4.1 $ ansible
Usage: ansible <host-pattern> [options]
Options:
-a MODULE_ARGS, --args=MODULE_ARGS
module arguments
--ask-become-pass ask for privilege escalation password
-k, --ask-pass ask for SSH password
--ask-su-pass ask for su password (deprecated, use become)
-K, --ask-sudo-pass ask for sudo password (deprecated, use become)
--ask-vault-pass ask for vault password
-B SECONDS, --background=SECONDS
run asynchronously, failing after X seconds
(default=N/A)
-b, --become run operations with become (nopasswd implied)
--become-method=BECOME_METHOD
privilege escalation method to use (default=sudo),
valid choices: [ sudo | su | pbrun | pfexec | runas ]
--become-user=BECOME_USER
run operations as this user (default=root)
-C, --check don't make any changes; instead, try to predict some
of the changes that may occur
-c CONNECTION, --connection=CONNECTION
connection type to use (default=smart)
-e EXTRA_VARS, --extra-vars=EXTRA_VARS
set additional variables as key=value or YAML/JSON
-f FORKS, --forks=FORKS
specify number of parallel processes to use
(default=5)
-h, --help show this help message and exit
-i INVENTORY, --inventory-file=INVENTORY
specify inventory host file
(default=/etc/ansible/hosts)
-l SUBSET, --limit=SUBSET
further limit selected hosts to an additional pattern
--list-hosts outputs a list of matching hosts; does not execute
anything else
-m MODULE_NAME, --module-name=MODULE_NAME
module name to execute (default=command)
-M MODULE_PATH, --module-path=MODULE_PATH
specify path(s) to module library (default=None)
-o, --one-line condense output
-P POLL_INTERVAL, --poll=POLL_INTERVAL
set the poll interval if using -B (default=15)
--private-key=PRIVATE_KEY_FILE
use this file to authenticate the connection
-S, --su run operations with su (deprecated, use become)
-R SU_USER, --su-user=SU_USER
run operations with su as this user (default=root)
(deprecated, use become)
-s, --sudo run operations with sudo (nopasswd) (deprecated, use
become)
-U SUDO_USER, --sudo-user=SUDO_USER
desired sudo user (default=root) (deprecated, use
become)
-T TIMEOUT, --timeout=TIMEOUT
override the SSH timeout in seconds (default=10)
-t TREE, --tree=TREE log output to this directory
-u REMOTE_USER, --user=REMOTE_USER
connect as this user (default=c400093)
--vault-password-file=VAULT_PASSWORD_FILE
vault password file
-v, --verbose verbose mode (-vvv for more, -vvvv to enable
connection debugging)
--version show program's version number and exit
<强> -bash-4.1 $ 强>
PS:如果你能从“ yum erase python ”并输入“y”就可以远离它,祝你好运。
答案 1 :(得分:1)
OP中显示的大多数错误都是由于版本不匹配造成的。例如。 except: XXX as obj
语法为introduced in 2.6。
我希望情况复杂,因为您安装了2.4和2.6,然后使用sudo
来安装内容。
最好以root身份打开交互式shell,在通过yum
或pip
安装这么多python模块之前正确设置PATH和PYTHONPATH,这样你就知道哪些模块安装了哪个前缀。< / p>
yum erase python
是愚蠢的,因为你可能很难学到。
所有这些都是yum配置错误:
http://74.125.194.100/yum/x86_64/6Server/%24YUM0/Server/../Packages/python-setuptools-0.6.10-3.el6.noarch.rpm: [Errno 14] PYCURL ERROR 22 - "The requested URL returned error: 404 Not Found"
Trying other mirror.
Error Downloading Packages:
python-setuptools-0.6.10-3.el6.noarch: failure: ../Packages/python-setuptools-0.6.10-3.el6.noarch.rpm from release.update: [Errno 256] No more mirrors to try.
总而言之ansible installation instructions非常可靠。
- 编辑 -
唯一的事情就是当PATH被设置为使用2.7.9 python(for 哪个python)和PYTHONPATH / PYTHONHOME都设置了,Linux 5.9版本 仍然在挑选python版本2.4站点包和实用程序 在Linux 5.9中严格依赖于python 2.4。在/ usr / xxx下 那时候我没有为python 2.7.9提供LIB文件夹 将整个Linux切换到6.6版本。而不是使用“制造 安装“为手动安装python,我用”make altinstall“这样 这两者可以并排坐着。 - Arun Sangal
在RHEL 5.x上:/usr/bin/python
即使你安装了2.6+(它会转到/usr/bin/python2.6
或/usr/bin/python26
或者类似的东西,它仍会保持2.4。所以默认的python仍然是2.4 (即使安装2.6 +后)
在RHEL 6.x上:默认情况下不安装python 2.4。所以/usr/bin/python
默认为2.6。所以默认的python是2.6。
大多数实用程序/脚本都将使用/usr/bin/python
执行,因此你觉得 Linux 5.9中的实用程序严格依赖于python 2.4'。
通常问题是在RHEL 5.x上使用/usr/bin/python
执行2.6+编写的脚本,即python 2.4。 “ AFAIK ”其他方式(使用2.6解释器运行2.4脚本)更兼容(不完全)。