22 lines
534 B
YAML
22 lines
534 B
YAML
---
|
|
- name: Update default gateway
|
|
hosts: hosts
|
|
become: true
|
|
vars:
|
|
new_gateway: "192.168.1.254"
|
|
|
|
tasks:
|
|
- name: Replace gateway line in interfaces file
|
|
lineinfile:
|
|
path: /etc/network/interfaces
|
|
regexp: '^(\s*)gateway\s+'
|
|
line: " gateway {{ new_gateway }}"
|
|
backrefs: yes
|
|
|
|
- name: Apply new default route immediately
|
|
command: ip route replace default via {{ new_gateway }}
|
|
|
|
- name: Restart networking
|
|
systemd:
|
|
name: networking
|
|
state: restarted |