# Passing variable in EC2 Inventory Plugin

**URL:** <https://forum.ansible.com/t/passing-variable-in-ec2-inventory-plugin/30800>\
**Category:** Ansible Project\
**Created:** [July 17, 2019, 1:07pm UTC](https://forum.ansible.com/t/passing-variable-in-ec2-inventory-plugin/30800 "2019-07-17T13:07:01Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![prasanth\_s](https://avatars.discourse-cdn.com/v4/letter/p/57b2e6/32.png) [@prasanth\_s](https://forum.ansible.com/u/prasanth_s)\
**Post date:** [July 17, 2019, 1:07pm UTC](https://forum.ansible.com/t/passing-variable-in-ec2-inventory-plugin/30800/1 "2019-07-17T13:07:01Z")

</div>

Hello Team,

I am using the EC2 Inventory plugin to build a dynamic inventory for ansible to run. The inventory is built based on certain ec2 instance tags mentioned in the filters section of the plugin config so that I can run ansible targetting specific instances based on their tags. Everything works as expected when I hard code the value of the tags in the plugin config directly. Unfortunately, when I try specifying a variable instead of the actual value, it doesn’t work. It just returns “[WARNING]: Could not match supplied host pattern, ignoring: role\_server”.

From the below config, I am passing a variable ‘var1’ as value for the tag ‘cluster\_name’. The value for this variable is mentioned in group\_vars/all. After some research, I found that group\_vars or host\_vars are acknowledged only on the task level and not on the inventory level. Do we have any workaround to make this work?

`

plugin: aws\_ec2  
regions:

- xxxxxxx  
keyed\_groups:
- key: tags.role  
prefix: role\_  
separator: “”  
groups:  
role\_all: “‘role’ in (tags|list)”  
compose:

# set the ansible\_host variable to connect with the private IP address without changing the hostname

ansible\_host: private\_ip\_address  
filters:  
tag:role:

- server
- worker  
tag:cluster\_name:
- “{{ var1 }}”

`

Thanks,  
Prasanth
