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
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.
Thanks! I’m trying it out now.