# Error in module "No start of json char found" & "KeyError: 'access\_token'"

**URL:** <https://forum.ansible.com/t/error-in-module-no-start-of-json-char-found-keyerror-access-token/41369>\
**Category:** Get Help\
**Tags:** gcp, ansible\
**Created:** [March 27, 2025, 8:42am UTC](https://forum.ansible.com/t/error-in-module-no-start-of-json-char-found-keyerror-access-token/41369 "2025-03-27T08:42:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![iamroddo](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/iamroddo/32/321_2.png) [@iamroddo](https://forum.ansible.com/u/iamroddo)\
**Post date:** [March 27, 2025, 8:42am UTC](https://forum.ansible.com/t/error-in-module-no-start-of-json-char-found-keyerror-access-token/41369/1 "2025-03-27T08:42:52Z")

</div>

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.

```yaml
- 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.

```auto
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

```

---

<div class="post-metadata">

**Author:** ![chris](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/chris/32/293_2.png) [@chris](https://forum.ansible.com/u/chris)\
**Post date:** [March 27, 2025, 8:52am UTC](https://forum.ansible.com/t/error-in-module-no-start-of-json-char-found-keyerror-access-token/41369/2 "2025-03-27T08:52:35Z")

</div>

Is there an issue with the `access_token` does this return the expected result?

```yaml
- name: Debug access_token
  ansible.builtin.debug:
    msg: "{{ lookup('env', 'GCP_ACCESS_TOKEN') }}"

```

---

<div class="post-metadata">

**Author:** ![iamroddo](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/iamroddo/32/321_2.png) [@iamroddo](https://forum.ansible.com/u/iamroddo)\
**Post date:** [March 27, 2025, 9:57am UTC](https://forum.ansible.com/t/error-in-module-no-start-of-json-char-found-keyerror-access-token/41369/3 "2025-03-27T09:57:24Z")

</div>

The token looks fine and the same token works fine with another task in the same playbook.

```yaml
- name: Create test VMs in GCP
  hosts: all
  connection: local
  gather_facts: false
  tasks:
    - name: Create VMs
      google.cloud.gcp_compute_instance:
        name: '{{ inventory_hostname }}'
        machine_type: 'n1-standard-1'
        disks:
          - auto_delete: true
            boot: true
            initialize_params:
              source_image: '{{ source_image }}'
        network_interfaces:
          - network:
                selfLink: 'https://www.googleapis.com/compute/v1/projects/test-project/global/networks/lab'
            subnetwork:
              selfLink: 'https://compute.googleapis.com/compute/v1/projects/test-project/regions/us-central1/subnetworks/testsubnetwork'
        labels: '{{ labels | default ({}) }}'
        zone: 'us-central1-a'
        project: 'test-project'
        scopes:
          - 'https://www.googleapis.com/auth/compute'
        access_token: "{{ lookup('env', 'GCP_ACCESS_TOKEN') }}"
        auth_kind: 'accesstoken'
        service_accounts:
          - email: '{{ service_account }}'
            scopes:
              - 'https://www.googleapis.com/auth/cloud-platform'
      register: vm_result
      delegate_to: localhost

```
