我想使用Ansible将数据从Google vm实例发送到Google Pub/Sub。
看似合理的行动手册
---
- hosts: localhost
tasks:
- name: Write into log file
local_action:
shell echo "Hello" >> /etc/ansible/log.txt
- name: Send message through pubsub
shell: python pub.py project-344421 topic_test
args:
chdir: /home/pubsub 错误
"msg": "non-zero return code",
"rc": 1,
"start": "2020-04-14 18:20:00.723265",
"stderr": "Traceback (most recent call last):\n File \"pub.py\", line 22, in <module>\n from google.cloud import pubsub_v1\nImportError: No module named google.cloud",
"stderr_lines": [
"Traceback (most recent call last):",
" File \"pub.py\", line 22, in <module>",
" from google.cloud import pubsub_v1",
"ImportError: No module named google.cloud"
],
"stdout": "",
"stdout_lines": []手动使用python pub.py project-344421 topic_test可正常运行script pub.py
输出
der_topic
Published message Hello
now has message ID 874436722336138
Published 1 message(s).已安装模块google.cloud、google-cloud-pubsub和google-auth
pip install --upgrade google-cloud
pip install --upgrade google-cloud-pubsub
pip install --upgrade google-auth 发布于 2020-04-15 02:46:16
Ansible使用的python可执行文件可能与您在命令行中使用的不同。
使用以下命令找出它工作的可执行文件的路径...
$ which python...then将可执行文件的路径复制/粘贴到shell命令中。
- name: Send message through pubsub
shell: /<FULL>/<PATH>/python pub.py project-344421 topic_test
args:
chdir: /home/pubsub 如果这不起作用,那么您还可以尝试检查您的PYTHONPATH环境变量,看看它在终端和Ansible上下文中是否相同。
https://stackoverflow.com/questions/61214698
复制相似问题