-
-
Save odyssey4me/7def43fef79564edc7aa6d918f344135 to your computer and use it in GitHub Desktop.
mbuil
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ ansible-playbook test.yml | |
[WARNING]: Unable to parse /etc/ansible/hosts as an inventory source | |
[WARNING]: No inventory was parsed, only implicit localhost is available | |
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all' | |
PLAY [localhost] ********************************************************************************************************************************* | |
TASK [set_fact] ********************************************************************************************************************************** | |
ok: [localhost] | |
TASK [debug] ************************************************************************************************************************************* | |
ok: [localhost] => { | |
"msg": { | |
"address": "2.2.2.2" | |
} | |
} | |
PLAY RECAP *************************************************************************************************************************************** | |
localhost : ok=2 changed=0 unreachable=0 failed=0 | |
$ ansible-playbook test.yml -e mgmt_vlan=native | |
[WARNING]: Unable to parse /etc/ansible/hosts as an inventory source | |
[WARNING]: No inventory was parsed, only implicit localhost is available | |
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all' | |
PLAY [localhost] ********************************************************************************************************************************* | |
TASK [set_fact] ********************************************************************************************************************************** | |
ok: [localhost] | |
TASK [debug] ************************************************************************************************************************************* | |
ok: [localhost] => { | |
"msg": { | |
"address": "1.1.1.1" | |
} | |
} | |
PLAY RECAP *************************************************************************************************************************************** | |
localhost : ok=2 changed=0 unreachable=0 failed=0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- hosts: localhost | |
connection: local | |
gather_facts: no | |
vars: | |
mgmt_interface: eth0 | |
mgmt_vlan: 10 | |
device: | |
"eth0": | |
address: "1.1.1.1" | |
"eth0.10": | |
address: "2.2.2.2" | |
tasks: | |
- set_fact: | |
device_to_get: "{{ (mgmt_vlan == 'native') | ternary(mgmt_interface, mgmt_interface ~ '.' ~ mgmt_vlan) }}" | |
- debug: | |
msg: "{{ device[device_to_get] }}" | |
- debug: | |
msg: >- | |
{%- if mgmt_vlan == 'native' %} | |
{%- set device_to_get2 = mgmt_interface %} | |
{%- else %} | |
{%- set device_to_get2 = mgmt_interface ~ '.' ~ mgmt_vlan %} | |
{%- endif %} | |
{{- device[device_to_get2] }} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment