# Ansible Google Pubsub

**URL:** <https://forum.ansible.com/t/ansible-google-pubsub/33780>\
**Category:** Ansible Project\
**Created:** [September 10, 2020, 3:54am UTC](https://forum.ansible.com/t/ansible-google-pubsub/33780 "2020-09-10T03:54:49Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yantram\_Cloud](https://avatars.discourse-cdn.com/v4/letter/y/c0e974/32.png) [@Yantram\_Cloud](https://forum.ansible.com/u/Yantram_Cloud)\
**Post date:** [September 10, 2020, 3:54am UTC](https://forum.ansible.com/t/ansible-google-pubsub/33780/1 "2020-09-10T03:54:49Z")

</div>

I am trying to create a subscription for google pubsub through ansible playbook.  
this is my task.

- name: create a subscription

```auto
  gcpubsub:
    topic: test-topic1
    state: present
    credentials_file: "{{ gcp_cred_file }}"
    project_id: "{{ gcp_project }}"

```

```auto

```

```auto
Now it does not seem to work,i have installed google-cloud-pubsub

```

```auto
getting this error regarding client.

```

```auto
Any help how can i debug this?

```

```auto
Here is the error.

```

```auto
The full traceback is:
Traceback (most recent call last):
  File "/home/rashmi/.ansible/tmp/ansible-tmp-1599709674.061256-7651-29288875173708/AnsiballZ_gcpubsub.py", line 102, in <module>
    _ansiballz_main()
  File "/home/rashmi/.ansible/tmp/ansible-tmp-1599709674.061256-7651-29288875173708/AnsiballZ_gcpubsub.py", line 94, in _ansiballz_main
    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
  File "/home/rashmi/.ansible/tmp/ansible-tmp-1599709674.061256-7651-29288875173708/AnsiballZ_gcpubsub.py", line 40, in invoke_module
    runpy.run_module(mod_name='ansible.modules.cloud.google.gcpubsub', init_globals=None, run_name=' __main__', alter_sys=True)
  File "/home/rashmi/anaconda3/lib/python3.7/runpy.py", line 205, in run_module
    return _run_module_code(code, init_globals, run_name, mod_spec)
  File "/home/rashmi/anaconda3/lib/python3.7/runpy.py", line 96, in _run_module_code
    mod_name, mod_spec, pkg_name, script_name)
  File "/home/rashmi/anaconda3/lib/python3.7/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/tmp/ansible_gcpubsub_payload_soisvl0x/ansible_gcpubsub_payload.zip/ansible/modules/cloud/google/gcpubsub.py", line 333, in <module>
  File "/tmp/ansible_gcpubsub_payload_soisvl0x/ansible_gcpubsub_payload.zip/ansible/modules/cloud/google/gcpubsub.py", line 265, in main
AttributeError: module 'google.cloud.pubsub' has no attribute 'Client'
fatal: [localhost]: FAILED! => {
    "changed": false,
    "module_stderr": "Traceback (most recent call last):\n File \"/home/rashmi/.ansible/tmp/ansible-tmp-1599709674.061256-7651-29288875173708/AnsiballZ_gcpubsub.py\", line 102, in <module>\n _ansiballz_main()\n File \"/home/rashmi/.ansible/tmp/ansible-tmp-1599709674.061256-7651-29288875173708/AnsiballZ_gcpubsub.py\", line 94, in _ansiballz_main\n invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n File \"/home/rashmi/.ansible/tmp/ansible-tmp-1599709674.061256-7651-29288875173708/AnsiballZ_gcpubsub.py\", line 40, in invoke_module\n runpy.run_module(mod_name='ansible.modules.cloud.google.gcpubsub', init_globals=None, run_name=' __main__', alter_sys=True)\n File \"/home/rashmi/anaconda3/lib/python3.7/runpy.py\", line 205, in run_module\n return _run_module_code(code, init_globals, run_name, mod_spec)\n File \"/home/rashmi/anaconda3/lib/python3.7/runpy.py\", line 96, in _run_module_code\n mod_name, mod_spec, pkg_name, script_name)\n File \"/home/rashmi/anaconda3/lib/python3.7/runpy.py\", line 85, in _run_code\n exec(code, run_globals)\n File \"/tmp/ansible_gcpubsub_payload_soisvl0x/ansible_gcpubsub_payload.zip/ansible/modules/cloud/google/gcpubsub.py\", line 333, in <module>\n File \"/tmp/ansible_gcpubsub_payload_soisvl0x/ansible_gcpubsub_payload.zip/ansible/modules/cloud/google/gcpubsub.py\", line 265, in main\nAttributeError: module 'google.cloud.pubsub' has no attribute 'Client'\n",
    "module_stdout": "",
    "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
    "rc": 1
}

PLAY RECAP ********************************************************************************************************************************************************************************************************************************
localhost : ok=3 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0   

```

```auto
Thanks

```

```auto

```

```auto

```

```auto

```

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [September 10, 2020, 6:16am UTC](https://forum.ansible.com/t/ansible-google-pubsub/33780/2 "2020-09-10T06:16:29Z")

</div>

ansible --version

What does the entire playbook look like?

---

<div class="post-metadata">

**Author:** ![Yantram\_Cloud](https://avatars.discourse-cdn.com/v4/letter/y/c0e974/32.png) [@Yantram\_Cloud](https://forum.ansible.com/u/Yantram_Cloud)\
**Post date:** [September 10, 2020, 8:59am UTC](https://forum.ansible.com/t/ansible-google-pubsub/33780/3 "2020-09-10T08:59:44Z")

</div>

We are writing a playbook with ansible gcp\_pubsub follwoing this.

[https://docs.ansible.com/ansible/2.3/gcpubsub\_module.html#requirements-on-host-that-executes-moduleIt](https://docs.ansible.com/ansible/2.3/gcpubsub_module.html#requirements-on-host-that-executes-moduleIt) errors out even in creating topic.

“gcp\_pubsub.yml”

- name: create a topic [gcpubsub]  
gcpubsub:  
topic: “{{ topic\_name }}”  
state: present  
project\_id: “{{ gcp\_project }}”  
credentials\_file: “{{ gcp\_cred\_file }}”

- name: create subscription[gcpubsub]  
gcpubsub:  
topic: “{{ topic\_name }}”  
subscription:  
name: “{{ subscription\_name }}”  
state: present  
project\_id: “{{ gcp\_project }}”  
credentials\_file: “{{ gcp\_cred\_file }}”

Just for info ,

However when i use gcp\_pubsub\_topic to create topic and gcp\_pubsub\_subscription to create subscription , it works. but this is limited only to these.

Thanks,

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [September 10, 2020, 1:25pm UTC](https://forum.ansible.com/t/ansible-google-pubsub/33780/4 "2020-09-10T13:25:34Z")

</div>

I meant:

1. what version of ansible are you using (ansible --version)  
2. what versions of google-auth and google-cloud-pubsub are you using (pip list)

The docs link you send is about ansible 2.3 which is ancient by now -  
not sure if you intended this though.

---

<div class="post-metadata">

**Author:** ![Yantram\_Cloud](https://avatars.discourse-cdn.com/v4/letter/y/c0e974/32.png) [@Yantram\_Cloud](https://forum.ansible.com/u/Yantram_Cloud)\
**Post date:** [September 10, 2020, 2:27pm UTC](https://forum.ansible.com/t/ansible-google-pubsub/33780/5 "2020-09-10T14:27:26Z")

</div>

Yes, i think it seems to be very old,

ansible 2.9.12

Name: google-cloud-pubsub  
Version: 1.7.0

Name: google-auth  
Version: 1.21.1
