# Ansible GCP dynamic Inventory Plugin How to pass Project ID

**URL:** <https://forum.ansible.com/t/ansible-gcp-dynamic-inventory-plugin-how-to-pass-project-id/36893>\
**Category:** Ansible Project\
**Tags:** gcp\
**Created:** [July 24, 2022, 8:21am UTC](https://forum.ansible.com/t/ansible-gcp-dynamic-inventory-plugin-how-to-pass-project-id/36893 "2022-07-24T08:21:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![A\_D](https://avatars.discourse-cdn.com/v4/letter/a/e19b73/32.png) [@A\_D](https://forum.ansible.com/u/A_D)\
**Post date:** [July 24, 2022, 8:21am UTC](https://forum.ansible.com/t/ansible-gcp-dynamic-inventory-plugin-how-to-pass-project-id/36893/1 "2022-07-24T08:21:14Z")

</div>

Hi Everyone,

I am using the dynamic inventory file for setting up Ansible for running configurations in GCP

# inventory.compute.gcp.yml

plugin: gcp\_compute # name the plugin you want to use (use `ansible-doc -t inventory -l` to list available plugins)  
projects:

- \<gcp\_project\_id\> # Id of your gcp project  
regions: # regions from your project you want to fetch inventory from (you can also use zones instead of regions if you target one or several specific zones)
- \<gcp\_project\_region\>  
filters:   
auth\_kind: serviceaccount # gcp authentication kind. with service account you should provide the service account json key file to authenticate  
service\_account\_file: \<service\_account\_file\>.json # Service account json keyfile

How do I set the project\_id as a variable?how can I pass the project ID from CLI when executing an ansible playbook? does ansible support jinja templating for inventory file? Please advise

---

<div class="post-metadata">

**Author:** ![Walter\_Rowe](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/walter_rowe/32/4506_2.png) [@Walter\_Rowe](https://forum.ansible.com/u/Walter_Rowe)\
**Post date:** [August 1, 2022, 12:40pm UTC](https://forum.ansible.com/t/ansible-gcp-dynamic-inventory-plugin-how-to-pass-project-id/36893/2 "2022-08-01T12:40:12Z")

</div>

Use templating to expand a variable name.

# inventory.compute.gcp.yml

plugin: gcp\_compute # name the plugin you want to use (use `ansible-doc -t inventory -l` to list available plugins)  
projects:

- **“{{ gcp\_project\_id }}”** # Id of your gcp project  
regions: # regions from your project you want to fetch inventory from (you can also use zones instead of regions if you target one or several specific zones)
- **"{{**  **gcp\_project\_region**  **}}"**  
filters:   
auth\_kind: serviceaccount # gcp authentication kind. with service account you should provide the service account json key file to authenticate  
service\_account\_file: **“{{ service\_account\_file }}.json”** # Service account json keyfile

Use the -e (extra var) command line option to specify the variable values on the command line.

**% ansible-playbook my\_gcp\_inventory.yml -e “gcp\_project\_id=XYZ123 gcp\_project\_region=ABC789 service\_account\_file=my\_gcp\_file”**
