Ansible Google Pubsub

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

  • name: create a subscription
  gcpubsub:
    topic: test-topic1
    state: present
    credentials_file: "{{ gcp_cred_file }}"
    project_id: "{{ gcp_project }}"

Now it does not seem to work,i have installed google-cloud-pubsub
getting this error regarding client.
Any help how can i debug this?
Here is the error.
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   

Thanks



ansible --version

What does the entire playbook look like?

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 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,

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.

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