How can I automatically change my IP address without knowing the network device name?

0
1
Asked By TechieGiraffe42 On

I'm trying to manage my network configurations across multiple servers using Ansible, but I've hit a snag. I typically set things up like this:

```
auto enp1s0
iface enp1s0 inet static
address 192.168.1.132/24
dns-nameservers 192.168.1.250 192.168.1.251
dns {'nameservers': ['192.168.1.131', '192.168.1.251'], 'search': []}
post-up route add default gw 192.168.1.251 || true
pre-down route del default gw 192.168.1.251 || true
```

The problem is that I need to specify the network device (e.g., `enp1s0`) to make this work. Is there a way to specify "the first real network device" automatically, without knowing their exact names?

1 Answer

Answered By CodeWizard99 On

You can use `{{ ansible_default_ipv4.interface }}` in your Ansible playbook to grab the default interface automatically. It's pretty handy! Check out the documentation for more details on Ansible facts.

CuriousCat88 -

Thanks! I’m trying it out now.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.