get name of network adapter

28 views
Skip to first unread message

nikita nipon

unread,
Apr 28, 2020, 1:33:25 PM4/28/20
to Ansible Project
I need to know the name of the network adapter. Since sometimes it is eth0 and other times ens192 for vwmare and rhev machines is it possible?

Dick Visser

unread,
Apr 28, 2020, 3:00:46 PM4/28/20
to ansible...@googlegroups.com
On Tue, 28 Apr 2020 at 19:33, nikita nipon
<antoniojime...@gmail.com> wrote:
>
> I need to know the name of the network adapter. Since sometimes it is eth0 and other times ens192 for vwmare and rhev machines is it possible?

You need to be more specific. What do you mean by "the" network
adapter? Which one?


--
Dick Visser
Trust & Identity Service Operations Manager
GÉANT

nikita nipon

unread,
Apr 29, 2020, 12:53:40 PM4/29/20
to Ansible Project
For example when i deploy one virtual machine from template,

To be able to run something that tells me: the network adapter is eht0, or is ens133 etc.


I want to extract the name of the network adapter that is generated with ansible


I have tried vmware_guest but it doesn't work

Juerg Ritter

unread,
Apr 29, 2020, 1:15:26 PM4/29/20
to ansible...@googlegroups.com
Hi,

The vmware_guest module talks to the vSphere API, which doesn't know about Linux internals (unless exposed by vmware tools). But after deployment, I suppose you could connect to the newly created system using ansible through SSH, and use ansible facts.

If you set gather_facts: yes in your playbook (which is default), you have access to a variable called ansible_interfaces which contains a list of all the interfaces. Here an example:

$ cat interfaces.yml
---
- name: Print all interfaces of Linux machine
  hosts: localhost
  tasks:
    - debug:
        var: ansible_interfaces
$ ansible-playbook interfaces.yml

PLAY [Print all interfaces of Linux machine] *************************************************************************************************************************************************

TASK [Gathering Facts] ***********************************************************************************************************************************************************************
ok: [localhost]

TASK [debug] *********************************************************************************************************************************************************************************
ok: [localhost] => {
    "ansible_interfaces": [
        "enp0s31f6",
        "ens1u1"
    ]
}

PLAY RECAP ***********************************************************************************************************************************************************************************
localhost                  : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0


I hope that helps!

Regards,
Jürg


--
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 ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/6fcba964-f6ee-4566-868a-79c0fde056f9%40googlegroups.com.


--

Jürg Ritter, RHCE

Consultant

Red Hat Switzerland

Europaallee 41

CH-8021 Zürich

jri...@redhat.com
M: +41-(0)79-715-09-90

nikita nipon

unread,
Apr 29, 2020, 2:29:44 PM4/29/20
to Ansible Project
Thanks for the reply


The problem I have is that I have to configure the machine with cloud init and I must know the network adapter, I cannot connect via ssh. 

Dick Visser

unread,
Apr 29, 2020, 2:54:48 PM4/29/20
to ansible...@googlegroups.com
Another strategy is to disable predictable interface names in your image, so your interfaces be eth0 etc again 

On Wed, 29 Apr 2020 at 20:29, nikita nipon <antoniojime...@gmail.com> wrote:
Thanks for the reply


The problem I have is that I have to configure the machine with cloud init and I must know the network adapter, I cannot connect via ssh. 

--
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 ansible-proje...@googlegroups.com.
--
Sent from a mobile device - please excuse the brevity, spelling and punctuation.
Reply all
Reply to author
Forward
0 new messages