如何在virtualenv中安装ansible?

时间:2016-05-05 04:57:39

标签: python virtualenv ansible

我需要在一个Ubuntu 12.04上创建一些虚拟环境,然后在另一个Ubuntu 12.04上运行ansible(我无法安装任何东西(没有Internet连接)。

我尝试在虚拟环境中安装Ansible:

export venv_name="ansible_virt_env"
mkdir ~/venv && cd ~/venv
echo "Virtualenv ${venv_name} directory" > README
virtualenv --no-site-packages --prompt="ansible" ${venv_name:-venv}
. ~/venv/${venv_name:-venv}/bin/activate
~/venv/${venv_name:-venv}/bin/pip install  -U pip
~/venv/${venv_name:-venv}/bin/pip install  -U setuptools
~/venv/${venv_name:-venv}/bin/pip install ansible

但它失败了:

ansibleroot@[RDE1.3]:~/venv# ~/venv/${venv_name:-venv}/bin/pip install  -U setuptools
Collecting setuptools    

/root/venv/ansible_virt_env/include/site/python2.7/cffi:         在pkg-config搜索路径中找不到包libffi。         也许你应该添加包含`libffi.pc'的目录。         到PKG_CONFIG_PATH环境变量         没有包' libffi'发现         在pkg-config搜索路径中找不到包libffi。

我安装了libffi-dev:     apt-get install libffi-dev

and ansible doen work:     /根/ VENV / ansible_virt_env / bin中/ ansible     错误!意外的例外:jinja2     完整的追溯是:

Traceback (most recent call last):
  File "/root/venv/ansible_virt_env/bin/ansible", line 75, in <module>
    from ansible.cli.adhoc import AdHocCLI as mycli
  File "/root/venv/ansible_virt_env/local/lib/python2.7/site-packages/ansible/cli/adhoc.py", line 28, in <module>
    from ansible.executor.task_queue_manager import TaskQueueManager
  File "/root/venv/ansible_virt_env/local/lib/python2.7/site-packages/ansible/executor/task_queue_manager.py", line 28, in <module>
    from ansible.executor.play_iterator import PlayIterator
  File "/root/venv/ansible_virt_env/local/lib/python2.7/site-packages/ansible/executor/play_iterator.py", line 29, in <module>
    from ansible.playbook.block import Block
  File "/root/venv/ansible_virt_env/local/lib/python2.7/site-packages/ansible/playbook/__init__.py", line 25, in <module>
    from ansible.playbook.play import Play
  File "/root/venv/ansible_virt_env/local/lib/python2.7/site-packages/ansible/playbook/play.py", line 27, in <module>
    from ansible.playbook.base import Base
  File "/root/venv/ansible_virt_env/local/lib/python2.7/site-packages/ansible/playbook/base.py", line 35, in <module>
    from ansible.parsing.dataloader import DataLoader
  File "/root/venv/ansible_virt_env/local/lib/python2.7/site-packages/ansible/parsing/dataloader.py", line 32, in <module>
    from ansible.parsing.vault import VaultLib
  File "/root/venv/ansible_virt_env/local/lib/python2.7/site-packages/ansible/parsing/vault/__init__.py", line 67, in <module>
    from cryptography.hazmat.primitives.hashes import SHA256 as c_SHA256
  File "/root/venv/ansible_virt_env/local/lib/python2.7/site-packages/cryptography/hazmat/primitives/hashes.py", line 15, in <module>
    from cryptography.hazmat.backends.interfaces import HashBackend
  File "/root/venv/ansible_virt_env/local/lib/python2.7/site-packages/cryptography/hazmat/backends/__init__.py", line 7, in <module>
    import pkg_resources
  File "/root/venv/ansible_virt_env/local/lib/python2.7/site-packages/distribute-0.6.24-py2.7.egg/pkg_resources.py", line 2707, in <module>
    working_set.require(__requires__)
  File "/root/venv/ansible_virt_env/local/lib/python2.7/site-packages/distribute-0.6.24-py2.7.egg/pkg_resources.py", line 686, in require
    needed = self.resolve(parse_requirements(requirements))
  File "/root/venv/ansible_virt_env/local/lib/python2.7/site-packages/distribute-0.6.24-py2.7.egg/pkg_resources.py", line 584, in resolve
    raise DistributionNotFound(req)
DistributionNotFound: jinja2

但是jinja2出现了:

ansibleroot@[RDE1.3]:~/venv# /root/venv/ansible_virt_env/bin/python
Python 2.7.3 (default, Dec 18 2014, 19:10:20)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import jinja2
>>>
ansibleroot@[RDE1.3]:~/venv# /root/venv/ansible_virt_env/bin/pip list
ansible (2.0.2.0)
cffi (1.6.0)
cryptography (1.3.2)
distribute (0.6.24)
enum34 (1.1.4)
idna (2.1)
ipaddress (1.0.16)
Jinja2 (2.8)
MarkupSafe (0.23)
paramiko (2.0.0)
pip (8.1.1)
pyasn1 (0.1.9)
pycparser (2.14)
pycrypto (2.6.1)
PyYAML (3.11)
setuptools (21.0.0)
six (1.10.0)

2 个答案:

答案 0 :(得分:2)

嗨,您需要安装此版本: pip install paramiko == 1.10 点子安装Jinja2 == 2.2

答案 1 :(得分:0)

对于它的价值,我在ansible 2.1.0.0(通过pip安装),Jinja 2.8,paramiko 2.0.1中遇到了同样的问题。 将ansible更新为2.2.1.0解决了问题(导致Jinja2更新到2.8.1)。