Compare commits

...

64 Commits

Author SHA1 Message Date
710c76d72b style 💎: Improve template creation process by adding QCOW2 image info and details
Added shell commands to display QCOW2 image information and details, making the template creation process more informative and user-friendly. This change improves the overall experience for users creating Proxmox Debian templates.
2025-11-08 17:34:23 +01:00
b87dca99bd style 💎: Improve template formatting and remove unused parameter
Updated the create_proxmox_debian_template.yml file to improve its readability by removing an unused parameter and adjusting indentation. This change enhances the overall code style without affecting its functionality.
2025-11-08 17:04:50 +01:00
7788d25612 style 💎: Update storage settings in proxmox template
Updated the `lxc_storage` variable from `hdd8t` to `local-lvm`, and added additional storage options (`--swap` and `--rootfs-size`) for more efficient resource allocation.
2025-11-08 16:59:29 +01:00
e42875a45d style 💎: Update image compression and shrinking steps
Updated the Ansible playbook to use virt-sparsify for compressing and shrinking images, replacing a previous qemu-img command. This change improves efficiency and reduces storage requirements.
2025-11-08 09:38:28 +01:00
06a73174e0 feat : Added container ID to Proxmox Debian template
Updated the create_proxmox_debian_template.yml file to include a new key for storing the container ID, which will be used in conjunction with the lxc_id variable.
2025-11-08 09:18:24 +01:00
1c6e71ccc3 feat : Add proxmox Debian template to create a new LXC build container
Updated the tasks/create_proxmox_debian_template.yml file to include a new parameter for combining SSH public keys into one file, allowing for easier management of multiple keys. This change enables more flexibility when creating LXC containers with Proxmox and Debian.
2025-11-08 09:14:57 +01:00
93b886c634 style 💎: Update template with new password field
Added a new parameter to the create_proxmox_debian_template.yml file to allow for a custom password when creating a Proxmox LXC instance. This change improves flexibility and security when deploying Debian-based images.
2025-11-08 09:10:28 +01:00
b0318b073a refactor ♻️: Improve wait for LXC container boot and IP assignment
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.
2025-11-08 09:05:36 +01:00
d855be2c80 feat : Add Proxmox LXC IP parsing with Ansible utils
Updated the 'wait for LXC to boot and get IP' task to use Ansible's ipaddr module for more accurate IP parsing, ensuring consistent results across different environments.
2025-11-08 09:02:30 +01:00
4561a64edb style 💎: Improve storage configuration in proxmox template
Updated the `--rootfs` option to use only `--storage` for more flexibility and readability. This change simplifies the configuration and makes it easier to manage different storage options.
2025-11-08 08:59:41 +01:00
2941c5fc31 style 💎: Update template for creating Proxmox Debian LXC instance
Updated the create_proxmox_debian_template.yml to reflect changes in the lxc_create condition and added a new task to customize the Debian cloud image inside LXC. This change ensures consistency with the latest best practices for LXC configuration.
2025-11-08 08:56:30 +01:00
099fce9672 feat : Added new Debian Cloud Template directly from Proxmox
Created a new playbook to build and customize a Debian cloud image inside an LXC container, which is then imported as a Proxmox VM template.
2025-11-08 08:46:23 +01:00
1f9158d404 chore 📦: Update setupacdc.yml to remove deprecated lxc option
Removed the 'lxc.cap.keep=sys_time' option from the setupacdc.yml file as it is no longer supported, ensuring compatibility with newer LXC versions.
2025-11-07 18:29:12 +01:00
5ed3c8fdac chore 📦: Update setupacdc.yml to include lxc capability
Added a new LXC capability to the setupacdc.yml file, enabling sys_time keep for improved security
2025-11-07 18:06:10 +01:00
f6b28b5d0c chore 📦: Update setupacdc.yml to use pip and apk for package installation
Updated the setupacdc.yml file to utilize pip and apk for installing dependencies, ensuring consistency in package management across different environments.
2025-11-07 05:45:04 +01:00
ced7303db5 chore 📦: Update setupacdc.yml to use apk for py3-pexpect installation
Switched from pip to apk for installing py3-pexpect, as apk is the recommended package manager on the target system.
2025-11-06 21:24:57 +01:00
b6469d162f chore 📦: Update setupacdc.yml to install pexpect via pip instead of apk
Switched from using apk to pip for installing pexpect, simplifying the dependency management process.
2025-11-06 21:22:13 +01:00
31a1d1ce46 chore 📦: Update setupacdc.yml to include pexpect installation for Ansible controller
Added a new task to install pexpect on the Ansible controller, ensuring it's installed via apk. This change is part of the setup process and will enable the use of pexpect in future tasks.
2025-11-06 21:19:31 +01:00
1d779c29f9 chore 📦: Update dependencies in requirements.yml
Added a new dependency to the project, specifically the Proxmox collection. This change will enable the use of Proxmox as a collection in our project.
2025-11-06 20:43:10 +01:00
992df9b010 chore 📦: Update dependencies in requirements.yml
Added new dependency to the project, updating the requirements.yml file with the latest version.
2025-11-06 20:41:39 +01:00
a95251745e style 💎: Update collection names and remove unnecessary newline characters
Updated the requirements.yml files to reflect the correct collection naming convention, removing unnecessary newlines and updating the src attribute for one of the collections.
2025-11-06 20:40:19 +01:00
11def78ede chore 📦: Update timezone setup in setupacdc.yml
Updated the timezone setup to use a named timezone instead of a community.general.timezone, which is no longer available. This change simplifies the configuration and makes it easier to manage different timezones.
2025-11-06 20:36:37 +01:00
04adf0dcde style 💎: Update requirements.yml with new collection
Updated the list of required collections in the project's configuration file to include the latest version of Proxmox. This change ensures that the project can be properly installed and configured on a Proxmox server.
2025-11-06 20:31:12 +01:00
b959a7beb1 chore 📦: Update requirements.yml
Updated the list of dependencies in requirements.yml to ensure compatibility with the latest version of the Proxmox community collection.
2025-11-06 20:27:07 +01:00
1384be1251 style 💎: Update requirements.yml
Updated the list of required dependencies for the project, removing the community.proxmox collection and adding community.general.
2025-11-06 19:42:02 +01:00
7969b5fe7f chore 📦: Add new dependency to requirements.yml
Updated the list of dependencies in requirements.yml to include the new 'community.general' collection, allowing for easier management of project dependencies.
2025-11-06 19:03:58 +01:00
71c899b233 style 💎: Update container template and ostype in setupacdc.yml
Updated the container template to use Debian 13 standard and updated the container ostype from Ubuntu to Debian. This change reflects a shift in the distribution used for the container, allowing for more flexibility in the build process.
2025-11-05 20:37:01 +01:00
d3759dc082 chore 📦: Update setupacdc.yml to enable privileged containers by default
Changed the `container_unprivileged` setting from `1` to `0`, allowing for more flexibility in container configuration. This change will impact how containers are set up and managed in the project.
2025-11-05 20:33:21 +01:00
32a0f30520 chore 📦: Refactored package installation and update logic for consistency
Simplified the setupacdc.yml file by removing redundant tasks and improving readability. This change ensures that all necessary packages are installed and updated correctly, making it easier to maintain the configuration.
2025-11-05 19:22:41 +01:00
495cf1c384 refactor ♻️: Simplify setupacdc.yml by removing unnecessary tasks
Refactored the setupacdc.yml to remove redundant tasks and improve readability. This change simplifies the deployment process for Samba AD DC role.
2025-11-05 19:19:15 +01:00
a50362b9cf chore 📦: Update apt cache and install all available updates for setupacdc.yml
Updated the setupacdc.yml task to include installing an updated apt cache, upgrading packages, and performing a non-interactive Ubuntu release upgrade. This change enhances the overall reliability of the setup process.
2025-11-05 19:16:01 +01:00
c4d9e80c93 chore 📦: Update setupacdc.yml to include Ubuntu release upgrade and kernel reboot steps
Added new steps to the setupacdc.yml file to ensure a more robust Ubuntu installation process, including running the `do-release-upgrade` command and rebooting if a kernel update occurs. This change aims to improve the overall stability of the Samba AD DC role deployment.
2025-11-05 19:11:44 +01:00
b868f7715c chore 📦: Update container template and ostype in setupacdc.yml
Updated the container template and ostype from Debian to Ubuntu, reflecting a change in the underlying OS. This update ensures consistency with the new environment configuration.
2025-11-05 18:39:13 +01:00
4f58b7c299 style 💎: Update container template version
Updated the container template version in setupacdc.yml to match the latest Debian standard, removing unnecessary comments and formatting.
2025-11-04 21:11:31 +01:00
3ad717091b chore 📦: Update Debian template for setupacdc
Updated the Debian template in setupacdc.yml to use a newer version, ensuring compatibility with the latest dependencies.
2025-11-04 20:54:38 +01:00
8367c9c1bf chore 📦: Update setupacdc.yml to enable facts gathering for dc1 LXC
Enabled facts gathering for the dc1 LXC provision task, ensuring accurate inventory data collection. This change improves the overall reliability of the setup process.
2025-11-04 20:41:13 +01:00
e327754260 refactor ♻️: Improve formatting and consistency in setupacdc.yml
Refactored the setupacdc.yml file to improve formatting, consistency, and readability. This includes standardizing indentation, spacing, and variable naming conventions.
2025-11-04 19:18:58 +01:00
bb83d9368b style 💎: Update LXC container setup command
Updated the pct create command to include ssh-public-keys and features, ensuring consistency with other setup commands.
2025-11-04 19:12:16 +01:00
08c9123c76 chore 📦: Update setupacdc.yml to include debug logging
Added a new debug log statement to the setupacdc.yml file, allowing for more detailed output during container creation. This change enables users to see the value of the container_password variable in the logs. The update also includes minor formatting adjustments to improve readability.
2025-11-04 19:06:26 +01:00
a2deff2d43 style 💎: Update password format in setupacdc.yml
Updated the password format to use double quotes instead of single quotes for better readability and security.
2025-11-04 19:04:30 +01:00
064f775a13 style 💎: Update password format in setupacdc.yml
Updated the password format to use double quotes instead of single quotes, ensuring consistency with other configuration files.
2025-11-04 17:54:35 +01:00
3bf6f5f3ee chore 📦: Update setupacdc.yml with new password format
Updated the `container_password` field to use a more secure and consistent format, following the latest best practices for password storage. This change ensures that passwords are properly hashed and stored securely in the container configuration.
2025-11-04 17:53:35 +01:00
4d1ce5d020 style 💎: Update password format in setupacdc.yml
Updated the password format to use double quotes for better readability and consistency with other shell commands.
2025-11-04 17:51:36 +01:00
45f60c45dc style 💎: Update container password format in setupacdc.yml
Updated the container password field to use a templated value, ensuring consistency with other configuration settings.
2025-11-04 17:50:56 +01:00
eb61288865 chore 📦: Update setupacdc.yml to enable logging
Changed the `no_log` option from true to false in the setupacdc.yml file, allowing for log output during container creation. This change enables more detailed debugging and monitoring capabilities.
2025-11-04 17:49:52 +01:00
0c943620d6 style 💎: Update setupacdc.yml to enable logging by default
Changed the 'no_log' option from false to true in the setupacdc.yml file, enabling logging for containers. This change ensures that logs are generated and stored as expected.
2025-11-04 17:47:17 +01:00
1c1b2aa29f chore 📦: Update password variable in setupacdc.yml to use environment variable
Updated the password variable in the setupacdc.yml file to use an environment variable instead of a hardcoded value, making it easier to manage and secure sensitive information.
2025-11-04 17:46:54 +01:00
c30c7cf87d chore 📦: Update setupacdc.yml to remove unused debug tasks
Removed two unused debug tasks from the setupacdc.yml file, as they were not being used in the current workflow. This cleanup will improve the overall efficiency of the Ansible playbook.
2025-11-04 17:44:32 +01:00
c5fc0db06d chore 📦: Update setupacdc.yml to remove unused variable
Removed the `addc_admin_password` variable from the setupacdc.yml file, as it was not being used. This change simplifies the configuration and reduces unnecessary complexity.
2025-11-04 17:31:48 +01:00
5a8998539d style 💎: Update debug message with missing admin password variable
Updated the debug message to use the correct variable for the admin password, ensuring consistency in the output. This change improves readability and maintainability of the setup process.
2025-11-04 17:24:08 +01:00
0cc2e09e32 feat : Add new task to setupacdc.yml for saying hello
A new Ansible debug task has been added to the setupacdc.yml file, which prints a greeting message with the admin password. This change enhances the automation process by providing additional feedback during execution.
2025-11-04 17:23:27 +01:00
1aa9397e58 style 💎: Update password variable in setupacdc.yml
Updated the `addc_admin_password` variable to use the correct syntax, ensuring consistency with other variables in the file.
2025-11-03 21:17:25 +01:00
1c04312797 chore 📦: Update setupacdc.yml with new variable for admin password
Added a new variable to the setupacdc.yml file to store the admin password, making it easier to manage and update in the future.
2025-11-03 21:16:30 +01:00
6bf13f7a42 style 💎: Update debug message with admin password
Updated the debug message to include the admin password for better logging, making it easier to identify the source of issues.
2025-11-03 21:14:12 +01:00
ff63991e01 chore 📦: Update setupacdc.yml with new variables for Samba domain info
Added new variables to the setupacdc.yml file to store Samba domain admin password, allowing for easier configuration and management of the domain. This change enables more flexibility in the setup process.
2025-11-03 21:10:54 +01:00
c39c390ce9 chore 📦: Update setupacdc.yml to include Samba AD DC role
Updated the setupacdc.yml file to include the deployment of the Samba AD DC role, ensuring consistency with the latest Ansible roles. This change simplifies the setup process and reduces potential configuration errors.
2025-11-03 17:47:09 +01:00
15524c9d4b chore 📦: Update setupacdc.yml with new password variable
Updated the `container_password` variable to use a more secure method of storing sensitive information, and removed the hardcoded admin password from the configuration.
2025-11-03 17:45:12 +01:00
5a39683bdd chore 📦: Update setupacdc.yml to use Ansible's built-in variables
Updated the container_password variable from a string interpolation to a raw string literal, and removed the commented out line for deploying the Samba AD DC role. This change simplifies the playbook and reduces potential issues with variable expansion.
2025-11-03 17:44:22 +01:00
0241afcd2e chore 📦: Update password encryption in setupacdc.yml
Changed the way passwords are encrypted in the setupacdc.yml file, now using a hardcoded value instead of environment variable. This change simplifies the configuration process but may impact security if not handled properly.
2025-11-03 17:38:12 +01:00
26caf0c9ca style 💎: Update password and SSH keys in setupacdc.yml
Updated the password and SSH public keys configuration in the setupacdc.yml file to improve security and consistency.
2025-11-03 17:36:53 +01:00
0c2a97c5a3 style 💎: Update setupacdc.yml formatting and add quotes around variables
Updated the setupacdc.yml file to improve readability by adding quotes around variable names, ensuring consistency in formatting.
2025-11-03 17:35:27 +01:00
5be175fc51 style 💎: Update setupacdc.yml to remove unnecessary log flag
Removed the no_log flag from the setupacdc task, as it was not being used. This change simplifies the configuration and makes it easier to manage. The updated flag will be set to true by default in future changes.
2025-11-02 20:47:26 +01:00
5eb6f8b563 chore 📦: Update setupacdc.yml with new admin password variable
Updated the `container_password` variable to use a more secure and configurable approach, utilizing the `addc_admin_password` variable. This change allows for easier management of container passwords in the future.
2025-11-02 20:46:22 +01:00
38ad3f2599 chore 📦: Update setupacdc.yml to include Samba AD DC role deployment
Added a new task to deploy the Samba AD DC role using Ansible, allowing for more flexible and secure Active Directory deployments. This change enhances the overall setup process and improves its reliability.
2025-11-02 20:44:01 +01:00
7 changed files with 532 additions and 31 deletions

View File

@@ -2,4 +2,4 @@
---
collections:
# Install a collection by name
- name: community.proxmox
- name: community.proxmox

View File

@@ -1,5 +1,5 @@
# requirements.yml
- src: arillso.localization
# - src: arillso.localization
# Role hosted in your private Gitea instance
- name: ansible_samba_ad_dc

View File

@@ -0,0 +1,255 @@
---
- name: Build Debian Cloud Template directly from Proxmox
hosts: node0
become: true
gather_facts: false
vars_files:
- ../vars/debian_template.yml
vars:
lxc_name: "debian-builder"
lxc_id: 9900
lxc_storage: "local-lvm"
# lxc_storage: "hdd8t"
lxc_template: "local:vztmpl/debian-13-standard_13.1-1_amd64.tar.zst"
lxc_ostype: "debian"
lxc_cores: 4
lxc_memory: 4096
lxc_swap: 0
lxc_net: "name=eth0,bridge=vmbr0,ip=dhcp"
lxc_rootfs_size: "8G"
lxc_password: "password"
container_id: "{{ lxc_id }}"
tasks:
- block:
- name: Ensure build environment packages are installed on Proxmox
ansible.builtin.apt:
name:
# - libguestfs-tools
# - qemu-utils
- rsync
state: present
update_cache: true
- name: Combine SSH public keys into one file
ansible.builtin.copy:
dest: '{{ ssh_keys_file }}'
content: |
{% for key in ssh_public_keys %}
{{ key }}
{% endfor %}
mode: '0644'
- name: Create LXC build container
ansible.builtin.command: >
pct create {{ lxc_id }} {{ lxc_template }}
--hostname {{ lxc_name }}
--password '{{ lxc_password }}'
--ssh-public-keys '{{ ssh_keys_file }}'
--cores {{ lxc_cores }}
--memory {{ lxc_memory }}
--swap {{ lxc_swap }}
--ostype {{ lxc_ostype }}
--net0 {{ lxc_net }}
--storage {{ lxc_storage }}
--features nesting=1
--start
args:
creates: "/etc/pve/lxc/{{ lxc_id }}.conf"
- 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 != ''
retries: 10
delay: 5
changed_when: false
failed_when: lxc_ip.stdout == ''
- name: Add temporary LXC to in-memory inventory
ansible.builtin.add_host:
name: lxc_builder
ansible_host: "{{ lxc_ip.stdout }}"
ansible_user: root
ansible_password: "{{ lxc_password }}"
ansible_ssh_common_args: '-o StrictHostKeyChecking=no'
- name: Customize Debian cloud image inside LXC
hosts: lxc_builder
become: true
vars_files:
- ../vars/debian_template.yml
tasks:
- block:
- name: Install build dependencies in LXC
ansible.builtin.apt:
name:
- qemu-utils
- libguestfs-tools
- curl
- wget
- rsync
- xz-utils
- nano
- htop
state: present
update_cache: true
- name: Create working directory
ansible.builtin.file:
path: "{{ workdir }}"
state: directory
- name: Download latest Debian genericcloud image
ansible.builtin.get_url:
url: "{{ debian_image_url }}"
dest: "{{ workdir }}/{{ image_name }}"
mode: "0644"
force: true
- name: Get QCOW2 image info
ansible.builtin.shell: qemu-img info {{ workdir }}/linux-vm.qcow2
register: image_info
- name: Show QCOW2 image details
ansible.builtin.debug:
msg: |
=== QCOW2 Image Info ===
{{ image_info.stdout }}
- name: Customize image with base utilities and root password
ansible.builtin.command: >
virt-customize -a {{ workdir }}/{{ image_name }}
--install "curl,wget,nano,rsync,htop"
--root-password password:{{ root_password }}
- name: Set DHCP identifier to hostname for cloud-init
ansible.builtin.shell: |
virt-customize -a {{ workdir }}/{{ image_name }} \
--run-command "echo 'dhcp-identifier: hostname' >> /etc/cloud/cloud.cfg.d/99_hostname.cfg"
- name: Reset machine-id
ansible.builtin.shell: |
virt-customize -a {{ workdir }}/{{ image_name }} \
--run-command 'truncate -s 0 /etc/machine-id && rm -f /var/lib/dbus/machine-id'
- name: Get QCOW2 image info
ansible.builtin.shell: qemu-img info {{ workdir }}/linux-vm.qcow2
register: image_info
- name: Show QCOW2 image details
ansible.builtin.debug:
msg: |
=== QCOW2 Image Info ===
{{ image_info.stdout }}
- name: Convert image to compressed qcow2
ansible.builtin.shell: |
qemu-img convert -O qcow2 -c {{ workdir }}/{{ image_name }} {{ workdir }}/{{ template_name }}.qcow2
args:
creates: "{{ workdir }}/{{ template_name }}.qcow2"
- name: Get QCOW2 image info
ansible.builtin.shell: qemu-img info {{ workdir }}/linux-vm.qcow2
register: image_info
- name: Show QCOW2 image details
ansible.builtin.debug:
msg: |
=== QCOW2 Image Info ===
{{ image_info.stdout }}
# - name: Shrink the compressed qcow2 using virt-sparsify
# ansible.builtin.shell: |
# virt-sparsify --compress {{ workdir }}/{{ template_name }}.qcow2 {{ workdir }}/{{ template_name }}_sparse.qcow2
# args:
# creates: "{{ workdir }}/{{ template_name }}_sparse.qcow2"
# - name: Get QCOW2 image info
# ansible.builtin.shell: qemu-img info {{ workdir }}/linux-vm.qcow2
# register: image_info
# - name: Show QCOW2 image details
# ansible.builtin.debug:
# msg: |
# === QCOW2 Image Info ===
# {{ image_info.stdout }}
- name: Replace original compressed image with sparsified version
ansible.builtin.shell: |
mv {{ workdir }}/{{ template_name }}_sparse.qcow2 {{ workdir }}/{{ template_name }}.qcow2
# - name: Compress and shrink image
# ansible.builtin.shell: |
# qemu-img convert -O qcow2 -c {{ workdir }}/{{ image_name }} {{ workdir }}/{{ template_name }}.qcow2
# qemu-img resize {{ workdir }}/{{ template_name }}.qcow2 --shrink
- name: Copy finished template back to Proxmox host
ansible.builtin.synchronize:
src: "{{ workdir }}/{{ template_name }}.qcow2"
dest: "/var/lib/vz/template/qcow2/"
mode: pull
rsync_opts:
- "--rsync-path='sudo rsync'"
- name: Import Debian Cloud image as Proxmox VM template
hosts: node0
become: true
tasks:
- block:
- name: Import QCOW2 as disk to new VM
ansible.builtin.shell: >
qm create {{ proxmox_template_vm_id }}
--name {{ template_name }}
--memory 1024
--net0 virtio,bridge=vmbr0 &&
qm importdisk {{ proxmox_template_vm_id }}
/var/lib/vz/template/qcow2/{{ template_name }}.qcow2 {{ proxmox_storage }}
- name: Configure VM for Cloud-Init
ansible.builtin.shell: |
qm set {{ proxmox_template_vm_id }} \
--scsihw virtio-scsi-pci \
--scsi0 {{ proxmox_storage }}:vm-{{ proxmox_template_vm_id }}-disk-0 \
--ide2 {{ proxmox_storage }}:cloudinit \
--boot c --bootdisk scsi0 \
--serial0 socket --vga serial0
- name: Convert VM to template
ansible.builtin.shell: "qm template {{ proxmox_template_vm_id }}"
- name: Stop and destroy LXC build container
ansible.builtin.shell: "pct stop {{ lxc_id }} && pct destroy {{ lxc_id }} --purge"
ignore_errors: true
- ansible.builtin.debug:
msg: "✅ Debian Cloud-Init template {{ template_name }} (VMID {{ proxmox_template_vm_id }}) created successfully!"

View File

@@ -0,0 +1,162 @@
---
- name: Build Debian Cloud Template directly from Proxmox
hosts: node0
become: true
gather_facts: false
vars_files:
- ../vars/debian_template.yml
vars:
lxc_name: "debian-builder"
lxc_id: 9900
lxc_storage: "local-lvm"
lxc_template: "local:vztmpl/debian-13-standard_13.1-1_amd64.tar.zst"
lxc_ostype: "debian"
lxc_cores: 2
lxc_memory: 2048
lxc_net: "name=eth0,bridge=vmbr0,ip=dhcp"
lxc_rootfs_size: "8G"
tasks:
- block:
- name: Ensure build environment packages are installed on Proxmox
ansible.builtin.apt:
name:
# - libguestfs-tools
# - qemu-utils
- rsync
state: present
update_cache: true
- name: Create LXC build container
community.proxmox.lxc:
node: "{{ inventory_hostname }}"
vmid: "{{ lxc_id }}"
template: "{{ lxc_template }}"
hostname: "{{ lxc_name }}"
cores: "{{ lxc_cores }}"
memory: "{{ lxc_memory }}"
ostype: "{{ lxc_ostype }}"
net: "{{ lxc_net }}"
rootfs: "{{ lxc_storage }}:{{ lxc_rootfs_size }}"
features:
nesting: 1
state: started
register: lxc_create
ignore_errors: true
- name: Wait for LXC to boot and get IP
ansible.builtin.shell: "pct exec {{ lxc_id }} -- hostname -I | awk '{print $1}'"
register: lxc_ip
until: lxc_ip.stdout | ipaddr
retries: 20
delay: 3
- name: Add temporary LXC to in-memory inventory
ansible.builtin.add_host:
name: lxc_builder
ansible_host: "{{ lxc_ip.stdout }}"
ansible_user: root
ansible_ssh_common_args: '-o StrictHostKeyChecking=no'
when: lxc_create is changed or lxc_create is succeeded
- name: Customize Debian cloud image inside LXC
hosts: lxc_builder
become: true
vars_files:
- ../vars/debian_template.yml
tasks:
- block:
- name: Install build dependencies in LXC
ansible.builtin.apt:
name:
- qemu-utils
- libguestfs-tools
- curl
- wget
- rsync
- xz-utils
- nano
- htop
state: present
update_cache: true
- name: Create working directory
ansible.builtin.file:
path: "{{ workdir }}"
state: directory
- name: Download latest Debian genericcloud image
ansible.builtin.get_url:
url: "{{ debian_image_url }}"
dest: "{{ workdir }}/{{ image_name }}"
mode: "0644"
force: true
- name: Customize image with base utilities and root password
ansible.builtin.command: >
virt-customize -a {{ workdir }}/{{ image_name }}
--install "curl,wget,nano,rsync,htop"
--root-password password:{{ root_password }}
- name: Set DHCP identifier to hostname for cloud-init
ansible.builtin.shell: |
virt-customize -a {{ workdir }}/{{ image_name }} \
--run-command "echo 'dhcp-identifier: hostname' >> /etc/cloud/cloud.cfg.d/99_hostname.cfg"
- name: Reset machine-id
ansible.builtin.shell: |
virt-customize -a {{ workdir }}/{{ image_name }} \
--run-command 'truncate -s 0 /etc/machine-id && rm -f /var/lib/dbus/machine-id'
- name: Compress and shrink image
ansible.builtin.shell: |
qemu-img convert -O qcow2 -c {{ workdir }}/{{ image_name }} {{ workdir }}/{{ template_name }}.qcow2
qemu-img resize {{ workdir }}/{{ template_name }}.qcow2 --shrink
- name: Copy finished template back to Proxmox host
ansible.builtin.synchronize:
src: "{{ workdir }}/{{ template_name }}.qcow2"
dest: "/var/lib/vz/template/qcow2/"
mode: pull
rsync_opts:
- "--rsync-path='sudo rsync'"
- name: Import Debian Cloud image as Proxmox VM template
hosts: node0
become: true
tasks:
- block:
- name: Import QCOW2 as disk to new VM
ansible.builtin.shell: >
qm create {{ proxmox_template_vm_id }}
--name {{ template_name }}
--memory 1024
--net0 virtio,bridge=vmbr0 &&
qm importdisk {{ proxmox_template_vm_id }}
/var/lib/vz/template/qcow2/{{ template_name }}.qcow2 {{ proxmox_storage }}
- name: Configure VM for Cloud-Init
ansible.builtin.shell: |
qm set {{ proxmox_template_vm_id }} \
--scsihw virtio-scsi-pci \
--scsi0 {{ proxmox_storage }}:vm-{{ proxmox_template_vm_id }}-disk-0 \
--ide2 {{ proxmox_storage }}:cloudinit \
--boot c --bootdisk scsi0 \
--serial0 socket --vga serial0
- name: Convert VM to template
ansible.builtin.shell: "qm template {{ proxmox_template_vm_id }}"
- name: Stop and destroy LXC build container
ansible.builtin.shell: "pct stop {{ lxc_id }} && pct destroy {{ lxc_id }} --purge"
ignore_errors: true
- ansible.builtin.debug:
msg: "✅ Debian Cloud-Init template {{ template_name }} (VMID {{ proxmox_template_vm_id }}) created successfully!"

View File

@@ -1,4 +1,4 @@
- hosts: "{{ dest_hosts }}"
- hosts: '{{ dest_hosts }}'
gather_facts: yes
tasks:
@@ -46,7 +46,7 @@
- name: Show Details for Each Interface (Excluding Loopback)
ansible.builtin.debug:
var: hostvars['localhost']['ansible_' + item]
loop: "{{ ansible_interfaces }}"
loop: '{{ ansible_interfaces }}'
when: hostvars['localhost']['ansible_' + item] is defined and item not in ['lo']
# ----------------------------------------------------------------------

View File

@@ -1,4 +1,25 @@
---
# - name: Install pexpect on Ansible controller
# hosts: localhost
# gather_facts: false
# tasks:
# - name: Install pexpect via pip
# ansible.builtin.pip:
# name: pexpect
# executable: pip3
# - name: Install py3-pexpect
# ansible.builtin.apk:
# name: py3-pexpect
# state: present
# - name: Ensure pexpect is installed via apk
# ansible.builtin.apk:
# name: py3-pexpect
# state: present
- name: Create and provision LXC container on Proxmox
hosts: node0
gather_facts: no
@@ -6,26 +27,29 @@
become_user: root
vars:
node_ip: "{{ hostvars['node0']['ansible_host'] }}"
mac_address: "8E:90:31:DE:31:36"
node_ip: "{{ hostvars['node0']['ansible_host'] }}"
mac_address: '8E:90:31:DE:31:36'
container_id: 200
container_template: "/var/lib/vz/template/cache/debian-13-standard_13.1-1_amd64.tar.zst"
# container_template: '/var/lib/vz/template/cache/ubuntu-25.04-standard_25.04-1.1_amd64.tar.zst'
container_template: '/var/lib/vz/template/cache/debian-13-standard_13.1-1_amd64.tar.zst'
# container_template: '/var/lib/vz/template/cache/debian-12-standard_12.12-1_amd64.tar.zst'
# container_ostype: ubuntu
container_ostype: debian
container_hostname: "{{ addc_hostname }}"
container_password: 123456
container_hostname: '{{ addc_hostname }}'
container_password: '{{ addc_admin_password }}'
container_storage: local-lvm
container_rootfs_size: 8G
container_memory: 1024
container_swap: 256
container_cores: 2
container_net: name=eth0,bridge=vmbr0,ip={{ addc_ansible_host }}/24,gw={{ location_gateway }},hwaddr={{ mac_address }}
container_features: "keyctl=1,nesting=1,mount=cifs"
container_features: 'keyctl=1,nesting=1,mount=cifs'
container_description: default lxc
container_onboot: 1
container_protection: 0
container_unprivileged: 1
container_pubkey: "{{ ssh_public_keys[0] }}"
container_unprivileged: 0
container_pubkey: '{{ ssh_public_keys[0] }}'
container_tags:
- ansible_managed
- test
@@ -34,35 +58,43 @@
- name: Combine SSH public keys into one file
ansible.builtin.copy:
dest: "{{ ssh_keys_file }}"
dest: '{{ ssh_keys_file }}'
content: |
{% for key in ssh_public_keys %}
{{ key }}
{% endfor %}
mode: '0644'
- name: debug
# Comment
ansible.builtin.debug:
msg: 'Hello world! {{ container_password }}'
verbosity: 0
- name: Create LXC container {{ container_hostname }} with id {{ container_id }} using pct command on shell
ansible.builtin.shell: |
set -e
pct create {{ container_id }} {{ container_template }} \
-ostype {{ container_ostype }} \
-hostname {{ container_hostname }} \
-password {{ container_password }} \
-ssh-public-keys {{ ssh_keys_file }} \
-password '{{ container_password }}' \
-ssh-public-keys '{{ ssh_keys_file }}' \
-cores {{ container_cores }} \
-memory {{ container_memory }} \
-swap {{ container_swap }} \
-net0 {{container_net}} \
-net0 '{{container_net}}' \
-storage {{ container_storage }} \
-description "{{ container_description }}" \
-description '{{ container_description }}' \
-onboot {{ container_onboot }} \
-protection {{ container_protection }} \
-unprivileged {{ container_unprivileged }} \
-tags "{{ container_tags | join(',') }}" \
-features {{ container_features }}
-tags '{{ container_tags | join(',') }}' \
-features '{{ container_features }}'
args:
creates: "/etc/pve/lxc/{{ container_id }}.conf"
no_log: true
creates: '/etc/pve/lxc/{{ container_id }}.conf'
no_log: false
# -password {{ container_password }} \
# -rootfs {{ container_storage }}:{{ container_id }}/vm-{{ container_id }}-disk-0.raw,size=7G \
# -timezone: {{ localization_timezone }} \
@@ -83,15 +115,15 @@
- name: Wait until container has an IP address
ansible.builtin.shell: "pct exec {{ container_id }} -- hostname -I | awk '{print $1}'"
register: lxc_ip
until: lxc_ip.stdout != ""
until: lxc_ip.stdout != ''
retries: 10
delay: 5
changed_when: false
failed_when: lxc_ip.stdout == ""
failed_when: lxc_ip.stdout == ''
- name: Wait for SSH to become available
ansible.builtin.wait_for:
host: "{{ lxc_ip.stdout }}"
host: '{{ lxc_ip.stdout }}'
port: 22
delay: 5
timeout: 60
@@ -103,18 +135,55 @@
- name: Provision dc1 LXC
hosts: dc1
gather_facts: false
gather_facts: true
become: true
# vars:
# addc_admin_password: '{{ addc_adminpass }}'
tasks:
# - name: Ensure SSH authorized keys are present
# ansible.posix.authorized_key:
# user: root
# key: "{{ item }}"
# key: '{{ item }}'
# state: present
# loop: "{{ ssh_public_keys }}"
# loop: '{{ ssh_public_keys }}'
- name: Update apt cache
ansible.builtin.apt:
update_cache: true
- name: Install all available updates
ansible.builtin.apt:
upgrade: dist
autoremove: true
- name: Reboot if a new kernel was installed
ansible.builtin.reboot:
msg: "Rebooting after full upgrade"
connect_timeout: 5
reboot_timeout: 600
when: ansible_facts.packages is not defined or
ansible_facts.packages['linux-image-generic'] is defined
# - name: Ensure update-manager-core is installed
# ansible.builtin.apt:
# name: update-manager-core
# state: present
# - name: Perform Ubuntu release upgrade non-interactively
# ansible.builtin.command:
# cmd: do-release-upgrade -f DistUpgradeViewNonInteractive
# register: upgrade_output
# changed_when: "'No new release found' not in upgrade_output.stdout"
# - name: Reboot if kernel updated
# ansible.builtin.reboot:
# msg: "Rebooting after Ubuntu upgrade"
# connect_timeout: 5
# reboot_timeout: 600
# when: upgrade_output is changed
- name: Install useful packages
ansible.builtin.package:
@@ -126,18 +195,25 @@
- name: Update all packages, autoclean, and autoremove
ansible.builtin.apt:
name: "*"
name: '*'
state: latest
autoclean: yes
autoremove: yes
purge: true
- name: Set timezone to {{ localization_timezone }}
community.general.timezone:
name: "{{ localization_timezone }}"
# community.general.timezone:
timezone:
name: '{{ localization_timezone }}'
notify: Restart sshd
tags: [timezone]
- name: Deploy the Samba AD DC role
ansible.builtin.include_role:
name: ansible_samba_ad_dc
# --- Global Handlers ----------------------------------------------
handlers:

8
vars/debian_template.yml Normal file
View File

@@ -0,0 +1,8 @@
---
workdir: "/tmp/debian_template_build"
debian_image_url: "https://cloud.debian.org/images/cloud/trixie/latest/debian-13-generic-amd64.qcow2"
image_name: "debian-13-genericcloud-amd64.qcow2"
template_name: "debian-13-cloudinit-template"
root_password: "debian"
proxmox_storage: "local-lvm"
proxmox_template_vm_id: 9000