On 24. nov. 2016 15:03, [email protected] wrote:
Number of network interfaces varies in our environment and we have atleast
5 variants, hardcoding is not an option.
This playbook need to check {{ ansible_interfaces }} and then get the
status of all available interfaces active status.
from the example snippet below
"ansible_eth1": {
"active": true,
"device": "eth1",
I am trying to set_fact which should return the dict like
"eth1status_active" = "yes"
eth0status_active" = "no"
...
ethxstatus_active = 'xxx'
I have lost just before the last task
tasks:
- name: get filesystem
setup: gather_subset=network
- name: set fact network_interfaces
set_fact: network_interfaces={{ ansible_interfaces }}
- name: set fact
set_fact: iface_item="ansible_{{ item }}"
with_items: "{{ ansible_interfaces }}"
register: iface_result
- name: make a list
set_fact: iface_list="{{ iface_result.results |
map(attribute='ansible_facts.iface_item') | list }}"
Please help me continue playing ..
You only need one task like this:
- set_fact:
"{{ item | replace('-', '_') }}status_active": "{{
hostvars[inventory_hostname]['ansible_' + item | replace('-',
'_')].active }}"
with_items: "{{ ansible_interfaces }}"
The replace is needed since dash in variable names is not allowed.
--
Kai Stian Olstad
--
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/5deee7ee-2d7f-c5b2-d16e-6a29471e8b1f%40olstad.com.
For more options, visit https://groups.google.com/d/optout.