--- - name: Update LXC config (no restart) no_log: true # defence in depth: the module already masks the API token secret delegate_to: localhost community.proxmox.proxmox: vmid: "{{ pve_lxc_vmid }}" node: "{{ pve_lxc_node }}" hostname: "{{ inventory_hostname }}" # Sent explicitly: community.proxmox 2.0.0 forwarded its argspec default "default" on # update, which Proxmox rejects (2.1.0 drops it). cmode: "{{ pve_lxc_cmode | default('tty') }}" memory: "{{ pve_lxc_memory }}" cores: "{{ pve_lxc_cores | default(omit) }}" swap: "{{ pve_lxc_swap | default(omit) }}" nameserver: "{{ pve_lxc_nameserver | default(omit) }}" netif: net0: >- {{ (['name=' ~ pve_lxc_net_interface, 'bridge=' ~ pve_lxc_net.bridge, 'ip=' ~ ansible_host ~ '/' ~ pve_lxc_net_prefix, 'gw=' ~ pve_lxc_net.gw, 'tag=' ~ pve_lxc_net.tag] + (['firewall=1'] if pve_lxc_firewall | bool else [])) | join(',') }} pubkey: "{{ pve_lxc_pubkey }}" features: "{{ pve_lxc_features if (pve_lxc_features | length > 0) else omit }}" onboot: "{{ __pve_lxc_effective_onboot }}" state: present update: true register: __pve_lxc_config_update - name: Restart LXC if config changed and restart-on-change is enabled no_log: true # defence in depth: the module already masks the API token secret # Proxmox only applies some config (e.g. `features`) on next container # start, not live via pct set. delegate_to: localhost community.proxmox.proxmox: vmid: "{{ pve_lxc_vmid }}" node: "{{ pve_lxc_node }}" hostname: "{{ inventory_hostname }}" state: restarted timeout: 300 when: - __pve_lxc_config_update.changed | default(false) - pve_lxc_restart_on_config_change - not ansible_check_mode - name: Resize disk if desired size is larger no_log: true # defence in depth: the module already masks the API token secret delegate_to: localhost community.proxmox.proxmox: vmid: "{{ pve_lxc_vmid }}" node: "{{ pve_lxc_node }}" hostname: "{{ inventory_hostname }}" disk: "{{ pve_lxc_disk }}" state: present update: true when: - pve_lxc_manage_disk - __pve_lxc_resize_disk - not ansible_check_mode register: __pve_lxc_disk_resize - name: Set disk resize API flag ansible.builtin.set_fact: __pve_lxc_disk_resized: >- {{ (__pve_lxc_disk_resized | default(false)) or (__pve_lxc_disk_resize.changed | default(false)) }} - name: Fail if disk resize was requested but not applied ansible.builtin.fail: msg: "Disk resize requested but Proxmox did not apply it" when: - pve_lxc_manage_disk - __pve_lxc_resize_disk - not __pve_lxc_disk_resized - not ansible_check_mode # Resize the filesystem inside the container using pct resize - name: Resize filesystem inside container delegate_to: "{{ pve_lxc_node }}" become: true ansible.builtin.command: > pct resize {{ pve_lxc_vmid }} rootfs {{ __pve_lxc_desired_disk_size }}G when: - pve_lxc_manage_disk - __pve_lxc_resize_disk - __pve_lxc_disk_resized | default(false) - not ansible_check_mode register: __pve_lxc_pct_resize_result changed_when: > __pve_lxc_pct_resize_result.rc == 0 and ( 'successfully resized' in __pve_lxc_pct_resize_result.stdout | lower or 'size of logical volume' in __pve_lxc_pct_resize_result.stdout | lower ) failed_when: > __pve_lxc_pct_resize_result.rc != 0 and 'no resize needed' not in (__pve_lxc_pct_resize_result.stderr | lower) - name: Restart LXC if disk was resized no_log: true # defence in depth: the module already masks the API token secret delegate_to: localhost community.proxmox.proxmox: vmid: "{{ pve_lxc_vmid }}" node: "{{ pve_lxc_node }}" hostname: "{{ inventory_hostname }}" state: restarted timeout: 300 when: - __pve_lxc_pct_resize_result is defined - __pve_lxc_pct_resize_result.changed - not ansible_check_mode - pve_lxc_reboot_if_required | bool