On 11/25/20 3:32 PM, Hiero-nymo wrote:
> Hi All,
>
> 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
>
> - name: debug
> debug:
> msg: "{{ item }}"
> loop: "{{ active.results }}"
>
> 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:
- set_fact:
my_nics: "{{ mynics | default([]) + [{ ansible_facts[item].device:
ansible_facts[item].active }] }}"
when:
- ansible_facts[item].type == 'ether'
loop: "{{ ansible_interfaces }}"
- debug:
var: my_nics
The list of interfaces is in the "ansible_interfaces" variable and each
interface is itself in the facts e.g.
"ansible_eth0" or "ansible_facts[eth0]".
Regards
Racke
>
> --
> 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]
> <mailto:[email protected]>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/dd7a6545-1c12-429a-9e8e-097e38ec7695n%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/dd7a6545-1c12-429a-9e8e-097e38ec7695n%40googlegroups.com?utm_medium=email&utm_source=footer>.
--
Ecommerce and Linux consulting + Perl and web application programming.
Debian and Sympa administration. Provisioning with Ansible.
--
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 view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/a0d9dc25-97aa-97db-425e-e34d0a4ab7df%40linuxia.de.
OpenPGP_signature
Description: OpenPGP digital signature
