From b0318b073a791a38a9cd4105a3462d15d5bcc96b Mon Sep 17 00:00:00 2001 From: Jose Date: Sat, 8 Nov 2025 09:05:36 +0100 Subject: [PATCH] =?UTF-8?q?refactor=20=E2=99=BB=EF=B8=8F:=20Improve=20wait?= =?UTF-8?q?=20for=20LXC=20container=20boot=20and=20IP=20assignment?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Enhanced the wait logic for LXC container boot and IP assignment by adding a check for container status and handling different scenarios. This change improves the reliability of the script. --- tasks/create_proxmox_debian_template.yml | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) 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: