I’m tried to check up which interfaces isn’t configured in Ubuntu20 to configure it.
So, first I check which interfaces are on the system. Then it will check if this device is UP or not. I want to retrieve which interface isn’t UP and put it a value in it: like :
ens160: 0
ens162: 1
For that in the next role later, I can configure the interface, when value=1.
name: check which interfaces exist
shell: find /sys/class/net -type l -not -lname ‘virtual’ -printf ‘%f\n’
register: ifconfig_result
name: check which interface is active
shell: ifconfig -a “{{ item }}”|head -1|grep -v UP || /bin/true
loop: “{{ ifconfig_result.stdout_lines }}”
register: active
I’ve seen with debug, two things: first one, both results are ok because /bin/true and secondly, the item is not the key.
For this reason I don’t know if it is possible in this case to retrieve this info.
Perhaps, there’s another easiest solution???
I'm tried to check up which interfaces isn't configured in Ubuntu20 to configure it.
So, first I check which interfaces are on the system. Then it will check if this device is UP or not. I want to retrieve
which interface isn't UP and put it a value in it: like :
ens160: 0
ens162: 1
For that in the next role later, I can configure the interface, when value=1.
- name: check which interfaces exist
shell: find /sys/class/net -type l -not -lname '*virtual*' -printf '%f\n'
register: ifconfig_result
- name: check which interface is active
shell: ifconfig -a "{{ item }}"|head -1|grep -v UP || /bin/true
loop: "{{ ifconfig_result.stdout_lines }}"
register: active
I've seen with debug, two things: first one, both results are ok because /bin/true and secondly, the item is not the key.
For this reason I don't know if it is possible in this case to retrieve this info.
Perhaps, there's another easiest solution???
As someone an idea?
Could someone enlighten me ?
Thank in advance and best regards
The information about the network interfaces is already in the Ansible facts, so you can do the following: