From: Kienan Stewart Date: Wed, 25 Sep 2024 16:19:13 +0000 (-0400) Subject: ansible: Manage multiple netplan configurations X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=c9e6740f9524c099c24fa97181bc63c4faa469f2;p=lttng-ci.git ansible: Manage multiple netplan configurations Change-Id: I8e3b59f1fafcaf1c94440b1e334026baa4fa4d00 Signed-off-by: Kienan Stewart --- diff --git a/automation/ansible/roles/netplan/defaults/main.yml b/automation/ansible/roles/netplan/defaults/main.yml index cb810d8..81552ea 100644 --- a/automation/ansible/roles/netplan/defaults/main.yml +++ b/automation/ansible/roles/netplan/defaults/main.yml @@ -1,4 +1,20 @@ --- 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 diff --git a/automation/ansible/roles/netplan/handlers/main.yml b/automation/ansible/roles/netplan/handlers/main.yml new file mode 100644 index 0000000..82755b7 --- /dev/null +++ b/automation/ansible/roles/netplan/handlers/main.yml @@ -0,0 +1,6 @@ +--- + +- name: Apply netplan + when: netplan_apply + ansible.builtin.command: + argv: ['netplan', 'apply'] diff --git a/automation/ansible/roles/netplan/tasks/config.yml b/automation/ansible/roles/netplan/tasks/config.yml new file mode 100644 index 0000000..8cb63e4 --- /dev/null +++ b/automation/ansible/roles/netplan/tasks/config.yml @@ -0,0 +1,22 @@ +--- +- 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' diff --git a/automation/ansible/roles/netplan/tasks/main.yml b/automation/ansible/roles/netplan/tasks/main.yml index 902a1e1..43476d3 100644 --- a/automation/ansible/roles/netplan/tasks/main.yml +++ b/automation/ansible/roles/netplan/tasks/main.yml @@ -5,13 +5,15 @@ 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: @@ -24,7 +26,11 @@ 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}}" diff --git a/automation/ansible/roles/netplan/templates/netplan.yaml.j2 b/automation/ansible/roles/netplan/templates/netplan.yaml.j2 new file mode 100644 index 0000000..73f71c5 --- /dev/null +++ b/automation/ansible/roles/netplan/templates/netplan.yaml.j2 @@ -0,0 +1 @@ +{{netplan_content | to_nice_yaml }}