diff --git a/tasks/create_proxmox_debian_template.yml b/tasks/create_proxmox_debian_template.yml index eecc43b..55475e2 100644 --- a/tasks/create_proxmox_debian_template.yml +++ b/tasks/create_proxmox_debian_template.yml @@ -44,12 +44,27 @@ args: creates: "/etc/pve/lxc/{{ lxc_id }}.conf" - - name: Wait for LXC to boot and get IP + - name: Check if LXC container {{ lxc_name }} is running + ansible.builtin.command: + cmd: pct status {{ lxc_id }} + register: pct_status + changed_when: false + + - name: Start the LXC container {{ lxc_name }} if stopped + ansible.builtin.command: + cmd: pct start {{ lxc_id }} + when: "'status: stopped' in pct_status.stdout" + register: start_result + changed_when: "'status: stopped' in pct_status.stdout" + + - name: Wait until container has an IP address ansible.builtin.shell: "pct exec {{ lxc_id }} -- hostname -I | awk '{print $1}'" register: lxc_ip - until: lxc_ip.stdout | ansible.utils.ipaddr - retries: 20 - delay: 3 + until: lxc_ip.stdout != '' + retries: 10 + delay: 5 + changed_when: false + failed_when: lxc_ip.stdout == '' - name: Add temporary LXC to in-memory inventory ansible.builtin.add_host: