---
netplan_manage: false
+
+# 0 or more non default config files
+# E.g.
+# netplan_configs:
+# - name: example
+# # filename: example # don't add '.yaml', defautls to name
+# # state: present
+# # dependencies: [] # list of packages to install to support this configuration
+# content:
+# network:
+# version: 2
+# ethernets:
+# eth1:
+# addresses:
+# ...
+netplan_configs: []
netplan_content: ''
netplan_apply: true
--- /dev/null
+---
+- when: item.dependencies|default([])
+ ansible.builtin.package:
+ name: "{{item.dependencies}}"
+ install_recommends: false
+
+- when: state == 'present'
+ ansible.builtin.template:
+ src: "netplan.yaml.j2"
+ dest: "{{filename}}"
+ mode: '0600'
+ owner: 'root'
+ group: 'root'
+ notify:
+ - 'Apply netplan'
+
+- when: state != 'present'
+ ansible.builtin.file:
+ path: "{{filename}}"
+ state: "{{state}}"
+ notify:
+ - 'Apply netplan'
ansible.builtin.apt:
name: netplan.io
- name: Update netplan default.yaml
+ when: netplan_content
ansible.builtin.copy:
content: "{{netplan_content}}"
dest: /etc/netplan/default.yaml
owner: root
group: root
mode: '0600'
- register: netplan_default_yaml
+ notify:
+ - 'Apply netplan'
- name: Disable ifupdown on Debian
when: ansible_distribution == "Debian"
block:
name: systemd-networkd
enabled: true
state: started
- - name: Apply netplan
- when: netplan_default_yaml.changed and netplan_apply
- ansible.builtin.command:
- argv: ['netplan', 'apply']
+ - name: Manage non-default netplan configurations
+ ansible.builtin.include_tasks:
+ file: config.yml
+ vars:
+ "filename": "/etc/netplan/{{item.filename|default(item.name)}}.yaml"
+ "netplan_content": "{{item.content}}"
+ "state": "{{item.state|default('present')}}"
+ loop: "{{netplan_configs}}"