Building configuration files from a template…
VOSS.J2
prompt {{ item.value.hostname }}
boot config flags tftpd
{% if item.value.sflow_enable %}
sflow agent-ip 192.168.211.10
sflow enable
{% endif %}
sflow agent-ip 192.168.211.10
sflow enable
{% endif %}
###
Playbook…
—
– name: Template Looping
hosts: localhostvars:
voss_devices: {
“vsp1”: {
“hostname”: “vsp1”,
“sflow_enable”: True
},
“vsp2”: {
“hostname”: “vsp2”,
“sflow_enable”: False
}
}
tasks:
– name: create switch config file
template:
src=/cygdrive/c/cygwin64/bin/voss.j2
dest=/cygdrive/c/cygwin64/bin/{{ item.key }}.config
with_dict: “{{ voss_devices }}”
– name: Template Looping
hosts: localhostvars:
voss_devices: {
“vsp1”: {
“hostname”: “vsp1”,
“sflow_enable”: True
},
“vsp2”: {
“hostname”: “vsp2”,
“sflow_enable”: False
}
}
tasks:
– name: create switch config file
template:
src=/cygdrive/c/cygwin64/bin/voss.j2
dest=/cygdrive/c/cygwin64/bin/{{ item.key }}.config
with_dict: “{{ voss_devices }}”
-bash-4.4$ cat vsp1.config
prompt vsp1
prompt vsp1
boot config flags tftpd
sflow agent-ip 192.168.211.10
sflow enable
sflow enable
-bash-4.4$ cat vsp2.config
prompt vsp2
prompt vsp2
boot config flags tftpd
-bash-4.4$