Compare commits

..

3 Commits

Author SHA1 Message Date
cb5342d0b9 style 💎: Update command to shell instead of command
Switched from `command` to `shell` in the `pct exec` task for better readability and flexibility.
2025-11-02 17:06:49 +01:00
98bf9f3c25 chore 📦: Update setupacdc.yml to improve container provisioning and cleanup processes
Updated the setupacdc.yml configuration to include additional checks for container IP address availability, improved package management, and enhanced timezone handling. These changes aim to streamline the provisioning process while maintaining a clean and efficient environment.
2025-11-02 16:59:48 +01:00
a71d196cc0 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.
2025-11-02 12:36:17 +01:00

View File

@@ -61,16 +61,24 @@
-features {{ container_features }}
args:
creates: "/etc/pve/lxc/{{ container_id }}.conf"
no_log: true
# -rootfs {{ container_storage }}:{{ container_id }}/vm-{{ container_id }}-disk-0.raw,size=7G \
# -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}'"
@@ -79,6 +87,7 @@
retries: 10
delay: 5
changed_when: false
failed_when: lxc_ip.stdout == ""
- name: Wait for SSH to become available
ansible.builtin.wait_for:
@@ -86,6 +95,11 @@
port: 22
delay: 5
timeout: 60
retries: 10
delay: 5
changed_when: false
# --- DC1 Provisioning Play --------------------------------------------
- name: Provision dc1 LXC
hosts: dc1
@@ -110,20 +124,25 @@
# - openssh-server
state: present
- name: Update all packages to their latest version
- name: Update all packages, autoclean, and autoremove
ansible.builtin.apt:
name: "*"
state: latest
- name: Remove useless packages from the cache
ansible.builtin.apt:
autoclean: yes
- name: Remove dependencies that are no longer required and purge their configuration files
ansible.builtin.apt:
autoremove: yes
purge: true
- name: Set timezone to {{ localization_timezone }}
community.general.timezone:
name: "{{ localization_timezone }}"
notify: Restart sshd
tags: [timezone]
# --- Global Handlers ----------------------------------------------
handlers:
- name: Restart sshd
ansible.builtin.service:
name: ssh
state: restarted
when: localization_timezone | bool