title: Ansible Collections: How to use Google Cloud Compute Engine inventory source
body: <p>What are the correct commands for using the inventory file along with a playbook when using Ansible Collections google.cloud.gcp_compute. You can find an example of the inventory file very similar to what I'm using at the bottom of this article <a href="https://docs.ansible.com/ansible/latest/collections/google/cloud/gcp_compute_inventory.html#ansible-collections-google-cloud-gcp-compute-inventory" rel="nofollow noreferrer">this article</a></p>
  <p>I'm using this <code>update.yml</code> playbook:</p>
  <pre><code>- name: Update apt-get repo and cache
    apt: update_cache=yes force_apt_get=yes cache_valid_time=3600
  </code></pre>
  <p>This is my <code>inventory-gcp_compute.yml</code> inventory file:</p>
  <pre><code>plugin: google.cloud.gcp_compute
  zones: # populate inventory with instances in these regions
    - us-central1-a
  projects:
    - vpn-server-sasp
  auth_kind: serviceaccount
  scopes:
    - 'https://www.googleapis.com/auth/cloud-platform'
    - 'https://www.googleapis.com/auth/compute.readonly'
  keyed_groups:
    # Create groups from GCE labels
    - prefix: gcp
      key: labels
  hostnames:
    # List host by name instead of the default public ip
    - name
  compose:
    # Set an inventory parameter to use the Public IP address to connect to the host
    # For Private ip use &quot;networkInterfaces[0].networkIP&quot;
    ansible_host: networkInterfaces[0].accessConfigs[0].natIP
  </code></pre>
  <p>I've tried these commands:</p>
  <pre><code>ansible-playbook -i inventory-gcp_compute.yml update.yml
  </code></pre>
  <p>I got this error:</p>
  <pre><code>ansible-playbook 2.9.14
    config file = /etc/ansible/ansible.cfg
    configured module search path = [u'/home/cheo/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
    ansible python module location = /usr/lib/python2.7/dist-packages/ansible
    executable location = /usr/bin/ansible-playbook
    python version = 2.7.17 (default, Jul 20 2020, 15:37:01) [GCC 7.5.0]
  Using /etc/ansible/ansible.cfg as config file
  host_list declined parsing /home/cheo/sergio/ansible-gce/inventory-gcp_compute.yml as it did not pass its verify_file() method
  virtualbox declined parsing /home/cheo/sergio/ansible-gce/inventory-gcp_compute.yml as it did not pass its verify_file() method
  [WARNING]:  * Failed to parse /home/cheo/sergio/ansible-gce/inventory-gcp_compute.yml with yaml plugin: Plugin configuration YAML file, not YAML inventory
    File &quot;/usr/lib/python2.7/dist-packages/ansible/inventory/manager.py&quot;, line 280, in parse_source
      plugin.parse(self._inventory, self._loader, source, cache=cache)
    File &quot;/usr/lib/python2.7/dist-packages/ansible/plugins/inventory/yaml.py&quot;, line 112, in parse
      raise AnsibleParserError('Plugin configuration YAML file, not YAML inventory')
  [WARNING]:  * Failed to parse /home/cheo/sergio/ansible-gce/inventory-gcp_compute.yml with constructed plugin: Incorrect plugin name in file: google.cloud.gcp_compute
    File &quot;/usr/lib/python2.7/dist-packages/ansible/inventory/manager.py&quot;, line 280, in parse_source
      plugin.parse(self._inventory, self._loader, source, cache=cache)
    File &quot;/usr/lib/python2.7/dist-packages/ansible/plugins/inventory/constructed.py&quot;, line 109, in parse
      self._read_config_data(path)
    File &quot;/usr/lib/python2.7/dist-packages/ansible/plugins/inventory/__init__.py&quot;, line 224, in _read_config_data
      raise AnsibleParserError(&quot;Incorrect plugin name in file: %s&quot; % config.get('plugin', 'none found'))
  [WARNING]: Unable to parse /home/cheo/sergio/ansible-gce/inventory-gcp_compute.yml as an inventory source
  [WARNING]: No inventory was parsed, only implicit localhost is available
  [WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'
  ERROR! 'apt' is not a valid attribute for a Play
  
  The error appears to be in '/home/cheo/sergio/ansible-gce/update.yml': line 3, column 3, but may
  be elsewhere in the file depending on the exact syntax problem.
  
  The offending line appears to be:
  
  
  - name: Update apt-get repo and cache
    ^ here
  
  </code></pre>