diff --git a/tasks/setupacdc.yml b/tasks/setupacdc.yml index cc082cd..17c35c0 100644 --- a/tasks/setupacdc.yml +++ b/tasks/setupacdc.yml @@ -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}'"