Ansible API : Expand variables

29 views
Skip to first unread message

amit bhagat

unread,
Feb 29, 2016, 11:05:23 AM2/29/16
to Ansible Project
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

amit bhagat

unread,
Mar 1, 2016, 2:36:14 AM3/1/16
to Ansible Project
Actually, the dictionary 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'}
Reply all
Reply to author
Forward
0 new messages