From 74f955cc3dc2a6921b3ff13fb62bf775017369a1 Mon Sep 17 00:00:00 2001 From: emo Date: Fri, 19 Jan 2024 00:27:49 +0100 Subject: [PATCH] Migrate code base from lxd to incus --- extensions/molecule/default/destroy.yml | 6 +++--- extensions/molecule/default/verify.yml | 4 ++-- roles/linux_container/tasks/container.yml | 6 +++--- roles/linux_container/tasks/openssh-server.yml | 14 +++++++------- roles/linux_container/tasks/ume.yml | 2 +- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/extensions/molecule/default/destroy.yml b/extensions/molecule/default/destroy.yml index 28f2d59..d8439ac 100644 --- a/extensions/molecule/default/destroy.yml +++ b/extensions/molecule/default/destroy.yml @@ -5,14 +5,14 @@ gather_facts: false tasks: - name: find current container state - ansible.builtin.command: lxc ls {{ item.name }} + ansible.builtin.command: incus ls {{ item.name }} register: state changed_when: false with_items: '{{ molecule_yml.platforms }}' - name: stop and remove running containers ansible.builtin.shell: cmd: | - lxc stop {{ item.name }} && \ - lxc rm {{ item.name }} + incus stop {{ item.name }} && \ + incus rm {{ item.name }} when: state.results[0].rc == 0 and "RUNNING" in state.results[0].stdout with_items: '{{ molecule_yml.platforms }}' diff --git a/extensions/molecule/default/verify.yml b/extensions/molecule/default/verify.yml index 676e469..42d5d19 100644 --- a/extensions/molecule/default/verify.yml +++ b/extensions/molecule/default/verify.yml @@ -4,14 +4,14 @@ gather_facts: false tasks: - name: find current container state - ansible.builtin.command: lxc ls {{ item.name }} + ansible.builtin.command: incus ls {{ item.name }} register: state with_items: '{{ molecule_yml.platforms }}' - name: verify launched container is running ansible.builtin.assert: that: state.results[0].rc == 0 and "RUNNING" in state.results[0].stdout - name: find container ip address - ansible.builtin.command: lxc ls -c=4 -f=compact {{ item.name }} + ansible.builtin.command: incus ls -c=4 -f=compact {{ item.name }} register: ipv4_raw with_items: '{{ molecule_yml.platforms }}' - name: set ipv4 address string as a fact diff --git a/roles/linux_container/tasks/container.yml b/roles/linux_container/tasks/container.yml index bd6e434..8e58a1f 100644 --- a/roles/linux_container/tasks/container.yml +++ b/roles/linux_container/tasks/container.yml @@ -1,19 +1,19 @@ --- - name: find current container state - ansible.builtin.command: lxc ls {{ lte_container_name }} + ansible.builtin.command: incus ls {{ lte_container_name }} register: container_state changed_when: false - name: launch debian bookworm linux container ansible.builtin.shell: cmd: | - lxc launch \ + incus launch \ images:debian/{{ lte_debian_version }}/cloud \ {{ lte_container_name }} when: (container_state.rc == 1) or ("RUNNING" not in container_state.stdout) - name: update apt cache and upgrade system packages ansible.builtin.shell: cmd: |- - lxc exec {{ lte_container_name }} -- \ + incus exec {{ lte_container_name }} -- \ bash -c \ '/usr/bin/apt update && /usr/bin/apt upgrade -y' changed_when: false diff --git a/roles/linux_container/tasks/openssh-server.yml b/roles/linux_container/tasks/openssh-server.yml index b773d17..ee4dda5 100644 --- a/roles/linux_container/tasks/openssh-server.yml +++ b/roles/linux_container/tasks/openssh-server.yml @@ -2,7 +2,7 @@ - name: find systemctl service for openssh-server ansible.builtin.shell: cmd: |- - lxc exec {{ lte_container_name }} -- \ + incus exec {{ lte_container_name }} -- \ systemctl status ssh.service register: ssh_service changed_when: false @@ -13,14 +13,14 @@ - name: install system package openssh-server ansible.builtin.shell: cmd: |- - lxc exec {{ lte_container_name }} -- \ + incus exec {{ lte_container_name }} -- \ apt install -y openssh-server register: ssh_pkg when: not ssh_service_exists - name: check openssh server configuration for root access ansible.builtin.shell: cmd: |- - lxc exec {{ lte_container_name }} -- \ + incus exec {{ lte_container_name }} -- \ grep -e "^PermitRootLogin yes$" /etc/ssh/sshd_config register: root_access changed_when: false @@ -31,7 +31,7 @@ - name: configure openssh server to allow root access via ssh ansible.builtin.shell: cmd: |- - lxc exec {{ lte_container_name }} -- \ + incus exec {{ lte_container_name }} -- \ sed -i "$ a PermitRootLogin yes" /etc/ssh/sshd_config register: sshd_config when: not ssh_root_login_allowed @@ -41,7 +41,7 @@ - name: enable openssh server systemd service ansible.builtin.shell: cmd: |- - lxc exec {{ lte_container_name }} -- \ + incus exec {{ lte_container_name }} -- \ systemctl enable --now ssh.service when: ssh_pkg_installed - name: set fact sshd_config_touched @@ -50,11 +50,11 @@ - name: restart openssh server systemd service ansible.builtin.shell: cmd: |- - lxc exec {{ lte_container_name }} -- \ + incus exec {{ lte_container_name }} -- \ systemctl restart ssh.service when: sshd_config_touched - name: find container ip address - ansible.builtin.command: lxc ls -c=4 -f=compact {{ lte_container_name }} + ansible.builtin.command: incus ls -c=4 -f=compact {{ lte_container_name }} register: ipv4 changed_when: false when: sshd_config_touched diff --git a/roles/linux_container/tasks/ume.yml b/roles/linux_container/tasks/ume.yml index 1a2adbe..5cee3a0 100644 --- a/roles/linux_container/tasks/ume.yml +++ b/roles/linux_container/tasks/ume.yml @@ -2,7 +2,7 @@ - name: change root user password in container ansible.builtin.shell: cmd: |- - lxc exec {{ lte_container_name }} -- \ + incus exec {{ lte_container_name }} -- \ bash -c \ 'echo "root:{{ lte_container_root_pwd }}" | chpasswd' changed_when: false