# get name of network  adapter

**URL:** <https://forum.ansible.com/t/get-name-of-network-adapter/32801>\
**Category:** Ansible Project\
**Created:** [April 28, 2020, 5:33pm UTC](https://forum.ansible.com/t/get-name-of-network-adapter/32801 "2020-04-28T17:33:25Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![nikita\_nipon](https://avatars.discourse-cdn.com/v4/letter/n/8edcca/32.png) [@nikita\_nipon](https://forum.ansible.com/u/nikita_nipon)\
**Post date:** [April 28, 2020, 5:33pm UTC](https://forum.ansible.com/t/get-name-of-network-adapter/32801/1 "2020-04-28T17:33:25Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [April 28, 2020, 7:00pm UTC](https://forum.ansible.com/t/get-name-of-network-adapter/32801/2 "2020-04-28T19:00:15Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![nikita\_nipon](https://avatars.discourse-cdn.com/v4/letter/n/8edcca/32.png) [@nikita\_nipon](https://forum.ansible.com/u/nikita_nipon)\
**Post date:** [April 29, 2020, 4:53pm UTC](https://forum.ansible.com/t/get-name-of-network-adapter/32801/3 "2020-04-29T16:53:39Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Juerg\_Ritter](https://avatars.discourse-cdn.com/v4/letter/j/7ea924/32.png) [@Juerg\_Ritter](https://forum.ansible.com/u/Juerg_Ritter)\
**Post date:** [April 29, 2020, 5:14pm UTC](https://forum.ansible.com/t/get-name-of-network-adapter/32801/4 "2020-04-29T17:14:36Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![nikita\_nipon](https://avatars.discourse-cdn.com/v4/letter/n/8edcca/32.png) [@nikita\_nipon](https://forum.ansible.com/u/nikita_nipon)\
**Post date:** [April 29, 2020, 6:29pm UTC](https://forum.ansible.com/t/get-name-of-network-adapter/32801/5 "2020-04-29T18:29:44Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [April 29, 2020, 6:54pm UTC](https://forum.ansible.com/t/get-name-of-network-adapter/32801/6 "2020-04-29T18:54:17Z")

</div>

Another strategy is to disable predictable interface names in your image, so your interfaces be eth0 etc again
