From 950a646cc52fc870c9203c3e879d4ef3ee519a52 Mon Sep 17 00:00:00 2001 From: Bertrand Lanson Date: Sat, 15 Apr 2023 18:14:37 +0200 Subject: [PATCH] added ci pipeline --- .gitlab-ci.yml | 82 +++++++++++ defaults/main.yml | 132 +++++++++--------- molecule/default/tests/test_default.py | 9 ++ .../with_custom_config/tests/test_default.py | 9 ++ tasks/configure.yml | 2 +- tasks/install.yml | 8 ++ 6 files changed, 175 insertions(+), 67 deletions(-) create mode 100644 .gitlab-ci.yml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..468a01d --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,82 @@ +--- +stages: + - verify + - test-default + - test-with-custom-config + +image: + name: registry.ednz.fr/forge/ansible-runner + +variables: + ANSIBLE_HOST_KEY_CHECKING: 'false' + ANSIBLE_FORCE_COLOR: 'true' + ANSIBLE_PYTHON_INTERPRETER: /usr/bin/python3 + DOCKER_AUTH_CONFIG: $CI_DOCKER_AUTH_CONFIG + +.stage-test-default: + stage: test-default + +.stage-test-with-custom-config: + stage: test-with-custom-config + +.variables-ubuntu-2004: + variables: + MOLECULE_TEST_OS: "ubuntu2004" + +.variables-ubuntu-2204: + variables: + MOLECULE_TEST_OS: "ubuntu2204" + +.variables-debian-11: + variables: + MOLECULE_TEST_OS: "debian11" + +.script-molecule-test-default: + script: + - molecule test + +.script-molecule-test-with-custom-config: + script: + - molecule test -s with_custom_config + +ansible-verify: + stage: verify + script: + - yamllint . -c .yamllint + - ansible-lint + +ansible-test-ubuntu-2004-default: + extends: + - .stage-test-default + - .variables-ubuntu-2004 + - .script-molecule-test-default + +ansible-test-ubuntu-2204-default: + extends: + - .stage-test-default + - .variables-ubuntu-2204 + - .script-molecule-test-default + +ansible-test-debian-11-default: + extends: + - .stage-test-default + - .variables-debian-11 + - .script-molecule-test-default + +ansible-test-ubuntu-2004-with-custom-config: + extends: + - .stage-test-with-custom-config + - .variables-ubuntu-2004 + - .script-molecule-test-with-custom-config + +ansible-test-ubuntu-2204-with-custom-config: + extends: + - .stage-test-with-custom-config + - .variables-ubuntu-2204 + - .script-molecule-test-with-custom-config + +ansible-test-debian-11-with-custom-config: + extends: + - .stage-test-with-custom-config + - .variables-debian-11 + - .script-molecule-test-with-custom-config diff --git a/defaults/main.yml b/defaults/main.yml index 278146a..d6514f8 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -7,69 +7,69 @@ manage_netplan_search_domain: example.org manage_netplan_install: true manage_netplan_apply: false manage_netplan_configuration: {} - # network: - # version: 2 - # ethernets: - # enp0s3: - # dhcp4: true - # enp0s8: - # addresses: - # - 192.168.250.10/24 - # - 192.168.250.11/24 - # nameservers: - # addresses: - # - 10.0.2.3 - # - 8.8.8.8 - # - 8.8.4.4 - # search: - # # Custom variable - # - "{{ manage_netplan_search_domain }}" - # gateway4: 192.168.250.1 - # optional: true - # routes: - # - to: 0.0.0.0/0 - # via: 9.9.9.9 - # on-link: true - # - to: 192.168.5.0/24 - # via: 192.168.5.1 - # table: 102 - # routing-policy: - # - from: 192.168.5.0/24 - # table: 102 - # lo: - # match: - # name: lo - # addresses: [7.7.7.7/32] - # wifis: - # wlp2s0b1: - # dhcp4: no - # dhcp6: no - # addresses: [192.168.0.21/24] - # gateway4: 192.168.0.1 - # access-points: - # "network_ssid_name": - # password: "**********" - # bonds: - # bond0: - # dhcp4: yes - # interfaces: - # - enp0s3 - # - enp4s0 - # parameters: - # # modes can be one of balance-rr, active-backup, balance-xor, broadcast, - # # 802.3ad, balance-tlb, and balance-alb. - # mode: active-backup - # primary: enp0s3 - # bridges: - # br0: - # dhcp4: yes - # interfaces: - # - enp0s3 - # br0: - # addresses: [10.3.99.25/24] - # interfaces: [vlan15] - # vlans: - # vlan15: - # accept-ra: no - # id: 15 - # link: enp0s25 +# network: +# version: 2 +# ethernets: +# enp0s3: +# dhcp4: true +# enp0s8: +# addresses: +# - 192.168.250.10/24 +# - 192.168.250.11/24 +# nameservers: +# addresses: +# - 10.0.2.3 +# - 8.8.8.8 +# - 8.8.4.4 +# search: +# # Custom variable +# - "{{ manage_netplan_search_domain }}" +# gateway4: 192.168.250.1 +# optional: true +# routes: +# - to: 0.0.0.0/0 +# via: 9.9.9.9 +# on-link: true +# - to: 192.168.5.0/24 +# via: 192.168.5.1 +# table: 102 +# routing-policy: +# - from: 192.168.5.0/24 +# table: 102 +# lo: +# match: +# name: lo +# addresses: [7.7.7.7/32] +# wifis: +# wlp2s0b1: +# dhcp4: no +# dhcp6: no +# addresses: [192.168.0.21/24] +# gateway4: 192.168.0.1 +# access-points: +# "network_ssid_name": +# password: "**********" +# bonds: +# bond0: +# dhcp4: yes +# interfaces: +# - enp0s3 +# - enp4s0 +# parameters: +# # modes can be one of balance-rr, active-backup, balance-xor, broadcast, +# # 802.3ad, balance-tlb, and balance-alb. +# mode: active-backup +# primary: enp0s3 +# bridges: +# br0: +# dhcp4: yes +# interfaces: +# - enp0s3 +# br0: +# addresses: [10.3.99.25/24] +# interfaces: [vlan15] +# vlans: +# vlan15: +# accept-ra: no +# id: 15 +# link: enp0s25 diff --git a/molecule/default/tests/test_default.py b/molecule/default/tests/test_default.py index 29799ac..cc481f0 100644 --- a/molecule/default/tests/test_default.py +++ b/molecule/default/tests/test_default.py @@ -16,3 +16,12 @@ def test_netplan_storage(host): assert etc_netplan.user == "root" assert etc_netplan.group =="root" assert etc_netplan.mode == 0o755 + +def test_netplan_config_file(host): + """Validate netplan config file.""" + etc_netplan_config = host.file("/etc/netplan/ansible-config.yaml") + assert etc_netplan_config.exists + assert etc_netplan_config.user == "root" + assert etc_netplan_config.group == "root" + assert etc_netplan_config.mode == 0o644 + assert etc_netplan_config.content_string != "" diff --git a/molecule/with_custom_config/tests/test_default.py b/molecule/with_custom_config/tests/test_default.py index 29799ac..4d46981 100644 --- a/molecule/with_custom_config/tests/test_default.py +++ b/molecule/with_custom_config/tests/test_default.py @@ -16,3 +16,12 @@ def test_netplan_storage(host): assert etc_netplan.user == "root" assert etc_netplan.group =="root" assert etc_netplan.mode == 0o755 + +def test_netplan_config_file(host): + """Validate netplan config file.""" + etc_netplan_config = host.file("/tmp/ansible-config.yaml") + assert etc_netplan_config.exists + assert etc_netplan_config.user == "root" + assert etc_netplan_config.group == "root" + assert etc_netplan_config.mode == 0o644 + assert etc_netplan_config.content_string != "" diff --git a/tasks/configure.yml b/tasks/configure.yml index 6542e29..ac8f478 100644 --- a/tasks/configure.yml +++ b/tasks/configure.yml @@ -1,6 +1,6 @@ --- # task/configure file for manage_netplan -- name: "Configuring Netplan" +- name: "Copy netplan configuration template into {{ manage_netplan_config_file }}" ansible.builtin.template: src: etc_netplan.yaml.j2 dest: "{{ manage_netplan_config_file }}" diff --git a/tasks/install.yml b/tasks/install.yml index a21793f..8b0be68 100644 --- a/tasks/install.yml +++ b/tasks/install.yml @@ -12,3 +12,11 @@ vars: manage_apt_packages_list: "{{ manage_netplan_networkmanager_pkg }}" when: manage_netplan_renderer == 'NetworkManager' + +- name: "Create directory /etc/netplan" + ansible.builtin.file: + path: "/etc/netplan" + state: directory + owner: "root" + group: "root" + mode: '0755'