I want to check status of Ethernet port whether it is up or down on remote server using Ansible?

  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking.
    – Community Bot
    Sep 8 '21 at 15:22

Assuming you can connect to the machine (say, using a local connection), you can interrogate the host facts.

It should expose a list ansible_interfaces, which will include the name of your ethernet interface. Each device will have a key in the facts. If your device is called eth0, you will have a dict called ansible_eth0.

The keys should include:

"ansible_eth0" {
  "active": true,
  "device": "eth0",
    "ipv4": {
      "address": "<address>",
      "broadcast": "<address>",
      "netmask": "<netmask>",
      "network": "<network>"
    "ipv6": [
        "address": "<ipv6_network>",
        "prefix": "64",
        "scope": "link"
    "macaddress": "<hw_address>",
    "module": "<kernel_module>",
    "mtu": XXX,
    "pciid": "XXX",
    "promisc": false,
    "type": "ether"

The active key there will tell you whether the device is active.

I would do it in the following way:

  • discover list of devices
  • find device that matches a name
  • discover status of the device.

A shorter way might be with a json_query filter

If you need to check that the device is ready from a remote execution, you could use a wait_for on a specific port that should become available when the device is up.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.