gpt4 book ai didi

python - 尽管 gce.py 有效,但 Ansible 中的 GCE 模块找不到 apache-libcloud

转载 作者:太空宇宙 更新时间:2023-11-03 11:01:22 26 4
gpt4 key购买 nike

我用 pip 安装了 ansible、a​​pache-libcloud。此外,我可以将 gcloud cli 和 ansible 作品用于任何与 gce 无关的剧本。

在ansible playbook中使用gce模块作为任务创建实例时,出现如下错误:

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

还有我写的playbook的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 支持的 ibcloud (0.13.3+)”。但是,从 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 导入的任务。脚本导入就好了!!!

最佳答案

设置 PYTHONPATH 解决了这个问题。例如:

$ export PYTHONPATH=/usr/local/lib/python2.7/site-packages/

关于python - 尽管 gce.py 有效,但 Ansible 中的 GCE 模块找不到 apache-libcloud,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31593638/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com