我用pip安装了ansible,apache-libcloud。另外,我可以将gcloud cli和ansible用于任何非gce相关的剧本。
当使用gce模块作为在ansible playbook中创建实例的任务时,会发生以下错误:
TASK: [Launch instances] ******************************************************
<127.0.0.1> REMOTE_MODULE gce instance_names=mm2 machine_type=f1-micro image=ubuntu-1204-precise-v20150625 zone=europe-west1-d service_account_email= pem_file=../pkey.pem project_id=fancystuff-11
<127.0.0.1> EXEC ['/bin/sh', '-c', 'mkdir -p $HOME/.ansible/tmp/ansible-tmp-1437669562.03-233461447935889 && chmod a+rx $HOME/.ansible/tmp/ansible-tmp-1437669562.03-233461447935889 && echo $HOME/.ansible/tmp/ansible-tmp-1437669562.03-233461447935889']
<127.0.0.1> PUT /var/folders/v4/ll0_f8lj7yl7yghb645h95q9ckfc19/T/tmpyDoPt9 TO /Users/d046179/.ansible/tmp/ansible-tmp-1437669562.03-233461447935889/gce
<127.0.0.1> EXEC ['/bin/sh', '-c', u'LANG=en_US.UTF-8 LC_CTYPE=en_US.UTF-8 /usr/bin/python /Users/d046179/.ansible/tmp/ansible-tmp-1437669562.03-233461447935889/gce; rm -rf /Users/d046179/.ansible/tmp/ansible-tmp-1437669562.03-233461447935889/ >/dev/null 2>&1']
failed: [localhost -> 127.0.0.1] => {"failed": true, "parsed": false}
failed=True msg='libcloud with GCE support (0.13.3+) required for this module'
FATAL: all hosts have already failed -- aborting
我写的剧本的site.yml:
name: Create a sandbox instance
hosts: localhost
vars:
names: mm2
machine_type: f1-micro
image: ubuntu-1204-precise-v20150625
zone: europe-west1-d
service_account_email: xxx@developer.gserviceaccount.com
pem_file: ../pkey.pem
project_id: fancystuff-11
tasks:
- name: Launch instances
local_action: gce instance_names={{names}} machine_type={{machine_type}}
image={{image}} zone={{zone}} service_account_email={{ service_account_email }}
pem_file={{ pem_file }} project_id={{ project_id }}
register: gce
gce云模块失败,并显示错误消息“此模块需要支持GCE(0.13.3+)的ibcloud”。 但是,从ansible github repo运行gce.py可以正常工作。 python脚本找到apache-libcloud库并打印一个包含所有正在运行的实例的json。此外,pip install apache-libcloud表示它已正确安装。
有什么我缺少的东西,比如指向python库的环境变量(PYTHONPATH)?
更新1:
我在gce任务之前包含了以下任务:
- name: install libcloud
pip: name=apache-libcloud
这也不会影响行为,也不会阻止任何错误消息。
更新2:
我添加了以下任务来检查可用的PYTHONPATH:
- name: Getting PYTHONPATH
local_action: shell python -c 'import sys; print(":".join(sys.path))'
register: pythonpath
- debug:
msg: "PYTHONPATH: {{ pythonpath.stdout }}"
返回以下内容:
PYTHONPATH: :/usr/local/lib/python2.7/site-packages/setuptools-17.1.1-py2.7.egg:/usr/local/lib/python2.7/site-packages/pip-7.0.3-py2.7.egg:/usr/local/lib/python2.7/site-packages:/usr/local/Cellar/python/2.7.10/Frameworks/Python.framework/Versions/2.7/lib/python27.zip:/usr/local/Cellar/python/2.7.10/Frameworks/Python.framework/Versions/2.7/lib/python2.7:/usr/local/Cellar/python/2.7.10/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin:/usr/local/Cellar/python/2.7.10/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac:/usr/local/Cellar/python/2.7.10/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages:/usr/local/Cellar/python/2.7.10/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk:/usr/local/Cellar/python/2.7.10/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old:/usr/local/Cellar/python/2.7.10/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload:/usr/local/lib/python2.7/site-packages:/Library/Python/2.7/site-packages
更新3:
我引入了自己的test.py脚本作为执行与gce ansible模块相同的apache-libcloud导入的任务。脚本导入很好!!!
答案 0 :(得分:2)
设置PYTHONPATH可以解决问题。例如:
size
答案 1 :(得分:1)
我正在使用OSX而且我为自己解决了这个问题。简答:用pip安装ansible。 (而不是例如酿造)
我检查了Ansible设置运行时的PYTHONPATH,看起来它与我的正常系统PYTHONPATH无关。例如。对我来说,我的系统PYTHONPATH是空的,并设置为例如mlazarov建议没有任何区别。我用ansible打印了它使用运行时的PYTHONPATH,它看起来像这样:
ok: [localhost] => {
"msg": "PYTHONPATH: :/usr/local/Cellar/ansible/1.9.4/libexec/lib/python2.7/site-packages:/usr/local/Cellar/ansible/1.9.4/libexec/vendor/lib/python2.7/site-packages:/Library/Frameworks/Python.framework/Versions/3.4/lib/python34.zip:/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4:/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/plat-darwin:/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/lib-dynload:/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages"
}
所以只有ansible自己的站点包和一些奇怪的Python3安装(我使用的是python2.7)
this讨论中的某些内容让我觉得它可能是ansible安装的问题,我的ansible安装了brew。我用pip重新安装它(简单地运行sudo pip install ansible),这解决了问题。现在PYTHONPATH ansible打印看起来好多了,我的virtualenv python安装在开始时,并且不再需要“libcloud并支持GCE(0.13.3+)”。
答案 2 :(得分:0)
我能够通过使用当前的site-packages文件夹设置PYTHONPATH环境变量(导出PYTHONPATH = / path / to / site-packages)来解决此问题。显然,ansible在模块执行期间建立了自己的环境,并忽略了python中可用的任何路径,除了来自环境变量PYTHONPATH的路径。
我发现这是一种特殊行为,未在ansible网站上记录。
答案 3 :(得分:0)
我有类似的环境设置。我在本节底部找到了一些信息:https://github.com/jlund/streisand#prerequisites
基本上有一些魔法文件你可以更新,所以brew&#d; d ansible将添加一个文件夹来搜索包:
mkdir -p ~/Library/Python/2.7/lib/python/site-packages
echo '/usr/local/lib/python2.7/site-packages' > ~/Library/Python/2.7/lib/python/site-packages/homebrew.pth
希望能为你修复它!
答案 4 :(得分:0)
在我的情况下是这样:
pip install apache-libcloud