Created
March 13, 2024 15:42
-
-
Save Nako/f602f11c9432a61a7f913a70d0523cd4 to your computer and use it in GitHub Desktop.
Ansibple playbook to disable cloudinit networking configuration, install ifupdown, and create/generate /etc/network/interfaces file on debian based systems
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- name: Disable cloudinit networking configuration, install ifupdown, and create/generate /etc/network/interfaces file | |
hosts: all | |
gather_facts: true | |
tasks: | |
- name: disable cloudinit networking configuration /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg | |
ansible.builtin.copy: | |
content: | | |
network: {config: disabled} | |
dest: /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg | |
mode: '0644' | |
- name: install ifupdown package | |
ansible.builtin.package: | |
name: ifupdown | |
state: present | |
- name: create interface file for the primary network interface default_ipv4.interface | |
ansible.builtin.copy: | |
content: | | |
# generated by ansible {{ lookup('pipe', 'date +%Y%m%d-%H%M%S') }} | |
source /etc/network/interfaces.d/* | |
# The loopback network interface | |
auto lo | |
iface lo inet loopback | |
# The primary network interface | |
allow-hotplug {{ ansible_default_ipv4.interface }} | |
iface {{ ansible_default_ipv4.interface }} inet static | |
address {{ ansible_default_ipv4.address }} | |
netmask {{ ansible_default_ipv4.netmask }} | |
gateway {{ ansible_default_ipv4.gateway }} | |
dns-nameservers {{ ansible_dns.nameservers[0] }} {{ ansible_dns.nameservers[0] }} | |
# /generated by ansible | |
dest: "/etc/network/interfaces" | |
- name: Reboot | |
ansible.builtin.reboot: | |
- name: Test connectivity | |
ping: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment