I am using the module google.cloud.gcp_dns_resource_record_set
(from the collection version 1.5.1) to create a DNS record in the task below.
- name: Create DNS record
google.cloud.gcp_dns_resource_record_set:
name: '{{ inventory_hostname }}.{{ dns_domain }}.'
managed_zone: '{{ gcp_dns_zone }}'
project: '{{ gcp_project }}'
auth_kind: 'accesstoken'
access_token: "{{ lookup('env', 'GCP_ACCESS_TOKEN') }}"
type: 'A'
ttl: 300
target:
- '{{ vm_result.networkInterfaces[0].networkIP }}'
delegate_to: localhost
My GCP account, with wihch the token is generated, is able to create a DNS record via the GCP web console. In the same playbook I am creating a VM using the same token and it works fine. However, when I run the task above, I get the error below.
TASK [Create DNS record] **************************************************************************************************************************************************************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: KeyError: 'access_token'
fatal: [ctrl-test -> localhost]: FAILED! => changed=false
module_stderr: |-
Traceback (most recent call last):
File "/root/.ansible/tmp/ansible-tmp-1743064794.8106873-30129-116452755121301/AnsiballZ_gcp_dns_resource_record_set.py", line 107, in <module>
_ansiballz_main()
File "/root/.ansible/tmp/ansible-tmp-1743064794.8106873-30129-116452755121301/AnsiballZ_gcp_dns_resource_record_set.py", line 99, in _ansiballz_main
invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
File "/root/.ansible/tmp/ansible-tmp-1743064794.8106873-30129-116452755121301/AnsiballZ_gcp_dns_resource_record_set.py", line 47, in invoke_module
runpy.run_module(mod_name='ansible_collections.google.cloud.plugins.modules.gcp_dns_resource_record_set', init_globals=dict(_module_fqn='ansible_collections.google.cloud.plugins.modules.gcp_dns_resource_record_set', _modlib_path=modlib_path),
File "<frozen runpy>", line 226, in run_module
File "<frozen runpy>", line 98, in _run_module_code
File "<frozen runpy>", line 88, in _run_code
File "/tmp/ansible_google.cloud.gcp_dns_resource_record_set_payload_tehfkhlt/ansible_google.cloud.gcp_dns_resource_record_set_payload.zip/ansible_collections/google/cloud/plugins/modules/gcp_dns_resource_record_set.py", line 503, in <module>
File "/tmp/ansible_google.cloud.gcp_dns_resource_record_set_payload_tehfkhlt/ansible_google.cloud.gcp_dns_resource_record_set_payload.zip/ansible_collections/google/cloud/plugins/modules/gcp_dns_resource_record_set.py", line 239, in main
File "/tmp/ansible_google.cloud.gcp_dns_resource_record_set_payload_tehfkhlt/ansible_google.cloud.gcp_dns_resource_record_set_payload.zip/ansible_collections/google/cloud/plugins/modules/gcp_dns_resource_record_set.py", line 250, in create
File "/tmp/ansible_google.cloud.gcp_dns_resource_record_set_payload_tehfkhlt/ansible_google.cloud.gcp_dns_resource_record_set_payload.zip/ansible_collections/google/cloud/plugins/modules/gcp_dns_resource_record_set.py", line 423, in create_change
File "/tmp/ansible_google.cloud.gcp_dns_resource_record_set_payload_tehfkhlt/ansible_google.cloud.gcp_dns_resource_record_set_payload.zip/ansible_collections/google/cloud/plugins/modules/gcp_dns_resource_record_set.py", line 440, in resource_to_change_request
File "/tmp/ansible_google.cloud.gcp_dns_resource_record_set_payload_tehfkhlt/ansible_google.cloud.gcp_dns_resource_record_set_payload.zip/ansible_collections/google/cloud/plugins/modules/gcp_dns_resource_record_set.py", line 428, in update_soa
File "/tmp/ansible_google.cloud.gcp_dns_resource_record_set_payload_tehfkhlt/ansible_google.cloud.gcp_dns_resource_record_set_payload.zip/ansible_collections/google/cloud/plugins/modules/gcp_dns_resource_record_set.py", line 415, in prefetch_soa_resource
File "/tmp/ansible_google.cloud.gcp_dns_resource_record_set_payload_tehfkhlt/ansible_google.cloud.gcp_dns_resource_record_set_payload.zip/ansible_collections/google/cloud/plugins/modules/gcp_dns_resource_record_set.py", line 295, in fetch_wrapped_resource
File "/tmp/ansible_google.cloud.gcp_dns_resource_record_set_payload_tehfkhlt/ansible_google.cloud.gcp_dns_resource_record_set_payload.zip/ansible_collections/google/cloud/plugins/modules/gcp_dns_resource_record_set.py", line 291, in fetch_resource
File "/tmp/ansible_google.cloud.gcp_dns_resource_record_set_payload_tehfkhlt/ansible_google.cloud.gcp_dns_resource_record_set_payload.zip/ansible_collections/google/cloud/plugins/module_utils/gcp_utils.py", line 85, in get
File "/tmp/ansible_google.cloud.gcp_dns_resource_record_set_payload_tehfkhlt/ansible_google.cloud.gcp_dns_resource_record_set_payload.zip/ansible_collections/google/cloud/plugins/module_utils/gcp_utils.py", line 150, in full_get
File "/tmp/ansible_google.cloud.gcp_dns_resource_record_set_payload_tehfkhlt/ansible_google.cloud.gcp_dns_resource_record_set_payload.zip/ansible_collections/google/cloud/plugins/module_utils/gcp_utils.py", line 194, in session
File "/tmp/ansible_google.cloud.gcp_dns_resource_record_set_payload_tehfkhlt/ansible_google.cloud.gcp_dns_resource_record_set_payload.zip/ansible_collections/google/cloud/plugins/module_utils/gcp_utils.py", line 257, in _credentials
KeyError: 'access_token'
module_stdout: ''
msg: |-
MODULE FAILURE: No start of json char found
See stdout/stderr for the exact error
rc: 1