Send data from Google Compute Engine to Google Pub/Sub using Ansible

22 views
Skip to first unread message

Jam Volkov

unread,
Apr 14, 2020, 2:39:17 PM4/14/20
to Ansible Project

I would like to send data from Google vm instance to Google Pub/Sub using Ansible.

Ansible playbook
---
- 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

Error

    "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": []

 Manually, the script pub.py runs properly with python pub.py project-344421 topic_test

 Output

der_topic
Published message Hello
 now has message ID
874436722336138
Published 1 message(s).

The modules google.cloud, google-cloud-pubsub and google-auth are installed

pip install --upgrade google-cloud
pip install
--upgrade google-cloud-pubsub
pip install
--upgrade google-auth


Message has been deleted

Jam Volkov

unread,
Apr 15, 2020, 7:45:11 AM4/15/20
to Ansible Project
 The executable path is different from the module location path. So I worked with virtualenv and it's ok now.
Reply all
Reply to author
Forward
0 new messages