Here is another example of how the referencing can take place. As can be seen "vsports" being pulled in the variable of ports
---
- name: test variables
hosts: localhost
gather_facts: no
vars:
pools: [ "pool1", "pool2" ]
vsports: [ "8443" , "443", "8089", "8184" ]
clusters:
cluster1:
server1:
server_port: 8081
service: apache
pools:
pool1:
virtual_servers:
- { name: "vs1", fq: "vs1.example.com", ports: "{{ vsports[0] }}" }
- { name: "vs2", fq: "vs2.example.com", ports: "{{ vsports[1] }}" }
pool2:
virtual_servers:
- { name: "vs3", fq: "vs3.example.com", ports: "{{ vsports[2] }}" }
- { name: "vs4", fq: "vs4.example.com", ports: "{{ vsports[3] }}" }
tasks:
- name: see the variables for server names
debug: msg="{{ item }}"
with_dict: "{{ clusters }}"
The Run of the playbook as seen here.
[root@ansible testplaybooks]# ansible-playbook 6play.yaml
PLAY [test variables] **************************************************************************************************************************
TASK [see the variables for server names] ******************************************************************************************************
ok: [localhost] => (item={'value': {u'server1': {u'pools': {u'pool2': {u'virtual_servers': [{u'fq': u'vs3.example.com', u'name': u'vs3', u'ports': u'8089'}, {u'fq': u'vs4.example.com', u'name': u'vs4', u'ports': u'8184'}]}, u'pool1': {u'virtual_servers': [{u'fq': u'vs1.example.com', u'name': u'vs1', u'ports': u'8443'}, {u'fq': u'vs2.example.com', u'name': u'vs2', u'ports': u'443'}]}}, u'service': u'apache', u'server_port': 8081}}, 'key': u'cluster1'}) => {
"changed": false,
"item": {
"key": "cluster1",
"value": {
"server1": {
"pools": {
"pool1": {
"virtual_servers": [
{
"fq": "vs1.example.com",
"name": "vs1",
"ports": "8443"
},
{
"fq": "vs2.example.com",
"name": "vs2",
"ports": "443"
}
]
},
"pool2": {
"virtual_servers": [
{
"fq": "vs3.example.com",
"name": "vs3",
"ports": "8089"
},
{
"fq": "vs4.example.com",
"name": "vs4",
"ports": "8184"
}
]
}
},
"server_port": 8081,
"service": "apache"
}
}
},
"msg": {
"key": "cluster1",
"value": {
"server1": {
"pools": {
"pool1": {
"virtual_servers": [
{
"fq": "vs1.example.com",
"name": "vs1",
"ports": "8443"
},
{
"fq": "vs2.example.com",
"name": "vs2",
"ports": "443"
}
]
},
"pool2": {
"virtual_servers": [
{
"fq": "vs3.example.com",
"name": "vs3",
"ports": "8089"
},
{
"fq": "vs4.example.com",
"name": "vs4",
"ports": "8184"
}
]
}
},
"server_port": 8081,
"service": "apache"
}
}
}
}
PLAY RECAP *************************************************************************************************************************************
localhost : ok=1 changed=0 unreachable=0 failed=0
No comments:
Post a Comment