For some servers in an inventory, i assign a range of ports. I want to use 
these ports in my playbooks while keeping them portable and compatible with 
any configuration. I am thinking of using variable for ports whose values 
are resolved via some script in inventory. Something like this:

--In Playbooks--
portValueUser: p1
hostName: localhost:p2
someURL: http://hostname:p3



--For first inventory, values of p1, p2, p3....---
p1: 5101
p2: 5102
p3 5103
...
...
p100:  5200


--For seconds inventory, values of p1, p2, p3....---
p1: 6201
p2: 6202
p3 6203
...
...
p100:  6300



This way, i can use a series of port values in my playbook which are 
defined by inventory(host vars). I am trying to figure out a way to really 
apply some logic in constructing these vars
Something like, in inventory/group_vars/all/load.yaml.j2
(please ignore the syntax errors, this is for illustration)

{% if a > b %}

{% for i = 1 to 100 and val = 5101 to 5200 %}

p{{i}} = val
{% endfor %}

{% else %}

{% for i = 1 to 100 and val = 6201 to 6300 %}

p{{i}} = val
{% endfor %}


{% endif %}

Remember the 2 main questions here:
1 - Can i really construct a large number of variables with loop like this ?
2 - How can i load or rather resolve a vars file like above via the 
inventory ?

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/99bebc74-aa14-47ec-b988-9e94ce69cafa%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to