# Ansible API : Expand variables

**URL:** <https://forum.ansible.com/t/ansible-api-expand-variables/20699>\
**Category:** Ansible Project\
**Created:** [February 29, 2016, 12:12am UTC](https://forum.ansible.com/t/ansible-api-expand-variables/20699 "2016-02-29T00:12:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![amit\_bhagat](https://avatars.discourse-cdn.com/v4/letter/a/43a26b/32.png) [@amit\_bhagat](https://forum.ansible.com/u/amit_bhagat)\
**Post date:** [February 29, 2016, 12:12am UTC](https://forum.ansible.com/t/ansible-api-expand-variables/20699/1 "2016-02-29T00:12:43Z")

</div>

I have written a custom module “filter\_prefix” that accepts “host” and “prefixes”.

I have a dictionary that looks like this -  
d2 = {‘4.4.4.4’:‘10.0.0.0/8’,‘11.0.0.0/8’, ‘5.5.5.5’:‘10.0.0.0/8’}

In the API script, I have -

hosts = d2.keys()  
device\_inventory = Inventory(hosts)

pb = Runner(  
module\_name = ‘filter\_prefix’,  
module\_args = ‘host={{ inventory\_hostname }} prefixes= ???’,  
transport = local,  
inventory = device\_inventory)

I would like to be able to pass appropriate ‘value’ to prefixes based on ‘host’ from d2 dictionary. I tried using -  
prefixes=“d2[‘{{ inventory\_hostname }}’]” but then it doesn’t expand d2.

I am running ansible version 1.9.2.

Any ideas?

Amit

---

<div class="post-metadata">

**Author:** ![amit\_bhagat](https://avatars.discourse-cdn.com/v4/letter/a/43a26b/32.png) [@amit\_bhagat](https://forum.ansible.com/u/amit_bhagat)\
**Post date:** [March 1, 2016, 7:36am UTC](https://forum.ansible.com/t/ansible-api-expand-variables/20699/2 "2016-03-01T07:36:14Z")

</div>

Actually, the dictionary looks like this-

d2 = {‘4.4.4.4’:‘[10.0.0.0/8](http://10.0.0.0/8),[11.0.0.0/8](http://11.0.0.0/8)’, ‘5.5.5.5’:‘[10.0.0.0/8](http://10.0.0.0/8)’}
