Migrate code base from lxd to incus

This commit is contained in:
emo 2024-01-19 00:27:49 +01:00
parent 07bbef3c81
commit 74f955cc3d
5 changed files with 16 additions and 16 deletions

View File

@ -5,14 +5,14 @@
gather_facts: false gather_facts: false
tasks: tasks:
- name: find current container state - name: find current container state
ansible.builtin.command: lxc ls {{ item.name }} ansible.builtin.command: incus ls {{ item.name }}
register: state register: state
changed_when: false changed_when: false
with_items: '{{ molecule_yml.platforms }}' with_items: '{{ molecule_yml.platforms }}'
- name: stop and remove running containers - name: stop and remove running containers
ansible.builtin.shell: ansible.builtin.shell:
cmd: | cmd: |
lxc stop {{ item.name }} && \ incus stop {{ item.name }} && \
lxc rm {{ item.name }} incus rm {{ item.name }}
when: state.results[0].rc == 0 and "RUNNING" in state.results[0].stdout when: state.results[0].rc == 0 and "RUNNING" in state.results[0].stdout
with_items: '{{ molecule_yml.platforms }}' with_items: '{{ molecule_yml.platforms }}'

View File

@ -4,14 +4,14 @@
gather_facts: false gather_facts: false
tasks: tasks:
- name: find current container state - name: find current container state
ansible.builtin.command: lxc ls {{ item.name }} ansible.builtin.command: incus ls {{ item.name }}
register: state register: state
with_items: '{{ molecule_yml.platforms }}' with_items: '{{ molecule_yml.platforms }}'
- name: verify launched container is running - name: verify launched container is running
ansible.builtin.assert: ansible.builtin.assert:
that: state.results[0].rc == 0 and "RUNNING" in state.results[0].stdout that: state.results[0].rc == 0 and "RUNNING" in state.results[0].stdout
- name: find container ip address - 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 register: ipv4_raw
with_items: '{{ molecule_yml.platforms }}' with_items: '{{ molecule_yml.platforms }}'
- name: set ipv4 address string as a fact - name: set ipv4 address string as a fact

View File

@ -1,19 +1,19 @@
--- ---
- name: find current container state - name: find current container state
ansible.builtin.command: lxc ls {{ lte_container_name }} ansible.builtin.command: incus ls {{ lte_container_name }}
register: container_state register: container_state
changed_when: false changed_when: false
- name: launch debian bookworm linux container - name: launch debian bookworm linux container
ansible.builtin.shell: ansible.builtin.shell:
cmd: | cmd: |
lxc launch \ incus launch \
images:debian/{{ lte_debian_version }}/cloud \ images:debian/{{ lte_debian_version }}/cloud \
{{ lte_container_name }} {{ lte_container_name }}
when: (container_state.rc == 1) or ("RUNNING" not in container_state.stdout) when: (container_state.rc == 1) or ("RUNNING" not in container_state.stdout)
- name: update apt cache and upgrade system packages - name: update apt cache and upgrade system packages
ansible.builtin.shell: ansible.builtin.shell:
cmd: |- cmd: |-
lxc exec {{ lte_container_name }} -- \ incus exec {{ lte_container_name }} -- \
bash -c \ bash -c \
'/usr/bin/apt update && /usr/bin/apt upgrade -y' '/usr/bin/apt update && /usr/bin/apt upgrade -y'
changed_when: false changed_when: false

View File

@ -2,7 +2,7 @@
- name: find systemctl service for openssh-server - name: find systemctl service for openssh-server
ansible.builtin.shell: ansible.builtin.shell:
cmd: |- cmd: |-
lxc exec {{ lte_container_name }} -- \ incus exec {{ lte_container_name }} -- \
systemctl status ssh.service systemctl status ssh.service
register: ssh_service register: ssh_service
changed_when: false changed_when: false
@ -13,14 +13,14 @@
- name: install system package openssh-server - name: install system package openssh-server
ansible.builtin.shell: ansible.builtin.shell:
cmd: |- cmd: |-
lxc exec {{ lte_container_name }} -- \ incus exec {{ lte_container_name }} -- \
apt install -y openssh-server apt install -y openssh-server
register: ssh_pkg register: ssh_pkg
when: not ssh_service_exists when: not ssh_service_exists
- name: check openssh server configuration for root access - name: check openssh server configuration for root access
ansible.builtin.shell: ansible.builtin.shell:
cmd: |- cmd: |-
lxc exec {{ lte_container_name }} -- \ incus exec {{ lte_container_name }} -- \
grep -e "^PermitRootLogin yes$" /etc/ssh/sshd_config grep -e "^PermitRootLogin yes$" /etc/ssh/sshd_config
register: root_access register: root_access
changed_when: false changed_when: false
@ -31,7 +31,7 @@
- name: configure openssh server to allow root access via ssh - name: configure openssh server to allow root access via ssh
ansible.builtin.shell: ansible.builtin.shell:
cmd: |- cmd: |-
lxc exec {{ lte_container_name }} -- \ incus exec {{ lte_container_name }} -- \
sed -i "$ a PermitRootLogin yes" /etc/ssh/sshd_config sed -i "$ a PermitRootLogin yes" /etc/ssh/sshd_config
register: sshd_config register: sshd_config
when: not ssh_root_login_allowed when: not ssh_root_login_allowed
@ -41,7 +41,7 @@
- name: enable openssh server systemd service - name: enable openssh server systemd service
ansible.builtin.shell: ansible.builtin.shell:
cmd: |- cmd: |-
lxc exec {{ lte_container_name }} -- \ incus exec {{ lte_container_name }} -- \
systemctl enable --now ssh.service systemctl enable --now ssh.service
when: ssh_pkg_installed when: ssh_pkg_installed
- name: set fact sshd_config_touched - name: set fact sshd_config_touched
@ -50,11 +50,11 @@
- name: restart openssh server systemd service - name: restart openssh server systemd service
ansible.builtin.shell: ansible.builtin.shell:
cmd: |- cmd: |-
lxc exec {{ lte_container_name }} -- \ incus exec {{ lte_container_name }} -- \
systemctl restart ssh.service systemctl restart ssh.service
when: sshd_config_touched when: sshd_config_touched
- name: find container ip address - 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 register: ipv4
changed_when: false changed_when: false
when: sshd_config_touched when: sshd_config_touched

View File

@ -2,7 +2,7 @@
- name: change root user password in container - name: change root user password in container
ansible.builtin.shell: ansible.builtin.shell:
cmd: |- cmd: |-
lxc exec {{ lte_container_name }} -- \ incus exec {{ lte_container_name }} -- \
bash -c \ bash -c \
'echo "root:{{ lte_container_root_pwd }}" | chpasswd' 'echo "root:{{ lte_container_root_pwd }}" | chpasswd'
changed_when: false changed_when: false