chore 📦: Update LXC container management in setupacdc.yml

Updated the Ansible playbook to check if a LXC container is running before starting it, and added a conditional statement to start the container only when it's stopped. This change improves the reliability of the setup process.
This commit is contained in:
2025-11-02 12:36:17 +01:00
parent fa263a4b27
commit a71d196cc0

View File

@@ -66,11 +66,18 @@
# -timezone: {{ localization_timezone }} \
- name: Start the LXC container {{ container_hostname }}
- name: Check if LXC container {{ container_hostname }} is running
ansible.builtin.command:
cmd: pct status {{ container_id }}
register: pct_status
changed_when: false
- name: Start the LXC container {{ container_hostname }} if stopped
ansible.builtin.command:
cmd: pct start {{ container_id }}
when: "'status: stopped' in pct_status.stdout"
register: start_result
changed_when: "'started' in start_result.stdout or start_result.rc == 0"
changed_when: "'status: stopped' in pct_status.stdout"
- name: Wait until container has an IP address
ansible.builtin.shell: "pct exec {{ container_id }} -- hostname -I | awk '{print $1}'"