Compare commits
66 Commits
dev
...
01331e6c80
| Author | SHA1 | Date | |
|---|---|---|---|
| 01331e6c80 | |||
| a69fdb50b0 | |||
| 710c76d72b | |||
| b87dca99bd | |||
| 7788d25612 | |||
| e42875a45d | |||
| 06a73174e0 | |||
| 1c6e71ccc3 | |||
| 93b886c634 | |||
| b0318b073a | |||
| d855be2c80 | |||
| 4561a64edb | |||
| 2941c5fc31 | |||
| 099fce9672 | |||
| 1f9158d404 | |||
| 5ed3c8fdac | |||
| f6b28b5d0c | |||
| ced7303db5 | |||
| b6469d162f | |||
| 31a1d1ce46 | |||
| 1d779c29f9 | |||
| 992df9b010 | |||
| a95251745e | |||
| 11def78ede | |||
| 04adf0dcde | |||
| b959a7beb1 | |||
| 1384be1251 | |||
| 7969b5fe7f | |||
| 71c899b233 | |||
| d3759dc082 | |||
| 32a0f30520 | |||
| 495cf1c384 | |||
| a50362b9cf | |||
| c4d9e80c93 | |||
| b868f7715c | |||
| 4f58b7c299 | |||
| 3ad717091b | |||
| 8367c9c1bf | |||
| e327754260 | |||
| bb83d9368b | |||
| 08c9123c76 | |||
| a2deff2d43 | |||
| 064f775a13 | |||
| 3bf6f5f3ee | |||
| 4d1ce5d020 | |||
| 45f60c45dc | |||
| eb61288865 | |||
| 0c943620d6 | |||
| 1c1b2aa29f | |||
| c30c7cf87d | |||
| c5fc0db06d | |||
| 5a8998539d | |||
| 0cc2e09e32 | |||
| 1aa9397e58 | |||
| 1c04312797 | |||
| 6bf13f7a42 | |||
| ff63991e01 | |||
| c39c390ce9 | |||
| 15524c9d4b | |||
| 5a39683bdd | |||
| 0241afcd2e | |||
| 26caf0c9ca | |||
| 0c2a97c5a3 | |||
| 5be175fc51 | |||
| 5eb6f8b563 | |||
| 38ad3f2599 |
@@ -2,4 +2,4 @@
|
|||||||
---
|
---
|
||||||
collections:
|
collections:
|
||||||
# Install a collection by name
|
# Install a collection by name
|
||||||
- name: community.proxmox
|
- name: community.proxmox
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
# requirements.yml
|
# requirements.yml
|
||||||
- src: arillso.localization
|
# - src: arillso.localization
|
||||||
|
|
||||||
# Role hosted in your private Gitea instance
|
# Role hosted in your private Gitea instance
|
||||||
- name: ansible_samba_ad_dc
|
- name: ansible_samba_ad_dc
|
||||||
|
|||||||
255
tasks/create_proxmox_debian_template.yml
Normal file
255
tasks/create_proxmox_debian_template.yml
Normal 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: push
|
||||||
|
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!"
|
||||||
162
tasks/create_proxmox_debian_template1.yml
Normal file
162
tasks/create_proxmox_debian_template1.yml
Normal 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!"
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
- hosts: "{{ dest_hosts }}"
|
- hosts: '{{ dest_hosts }}'
|
||||||
gather_facts: yes
|
gather_facts: yes
|
||||||
tasks:
|
tasks:
|
||||||
|
|
||||||
@@ -46,7 +46,7 @@
|
|||||||
- name: Show Details for Each Interface (Excluding Loopback)
|
- name: Show Details for Each Interface (Excluding Loopback)
|
||||||
ansible.builtin.debug:
|
ansible.builtin.debug:
|
||||||
var: hostvars['localhost']['ansible_' + item]
|
var: hostvars['localhost']['ansible_' + item]
|
||||||
loop: "{{ ansible_interfaces }}"
|
loop: '{{ ansible_interfaces }}'
|
||||||
when: hostvars['localhost']['ansible_' + item] is defined and item not in ['lo']
|
when: hostvars['localhost']['ansible_' + item] is defined and item not in ['lo']
|
||||||
|
|
||||||
# ----------------------------------------------------------------------
|
# ----------------------------------------------------------------------
|
||||||
|
|||||||
@@ -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
|
- name: Create and provision LXC container on Proxmox
|
||||||
hosts: node0
|
hosts: node0
|
||||||
gather_facts: no
|
gather_facts: no
|
||||||
@@ -6,26 +27,29 @@
|
|||||||
become_user: root
|
become_user: root
|
||||||
|
|
||||||
vars:
|
vars:
|
||||||
node_ip: "{{ hostvars['node0']['ansible_host'] }}"
|
node_ip: "{{ hostvars['node0']['ansible_host'] }}"
|
||||||
mac_address: "8E:90:31:DE:31:36"
|
mac_address: '8E:90:31:DE:31:36'
|
||||||
|
|
||||||
container_id: 200
|
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_ostype: debian
|
||||||
container_hostname: "{{ addc_hostname }}"
|
container_hostname: '{{ addc_hostname }}'
|
||||||
container_password: 123456
|
container_password: '{{ addc_admin_password }}'
|
||||||
container_storage: local-lvm
|
container_storage: local-lvm
|
||||||
container_rootfs_size: 8G
|
container_rootfs_size: 8G
|
||||||
container_memory: 1024
|
container_memory: 1024
|
||||||
container_swap: 256
|
container_swap: 256
|
||||||
container_cores: 2
|
container_cores: 2
|
||||||
container_net: name=eth0,bridge=vmbr0,ip={{ addc_ansible_host }}/24,gw={{ location_gateway }},hwaddr={{ mac_address }}
|
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_description: default lxc
|
||||||
container_onboot: 1
|
container_onboot: 1
|
||||||
container_protection: 0
|
container_protection: 0
|
||||||
container_unprivileged: 1
|
container_unprivileged: 0
|
||||||
container_pubkey: "{{ ssh_public_keys[0] }}"
|
container_pubkey: '{{ ssh_public_keys[0] }}'
|
||||||
container_tags:
|
container_tags:
|
||||||
- ansible_managed
|
- ansible_managed
|
||||||
- test
|
- test
|
||||||
@@ -34,35 +58,43 @@
|
|||||||
|
|
||||||
- name: Combine SSH public keys into one file
|
- name: Combine SSH public keys into one file
|
||||||
ansible.builtin.copy:
|
ansible.builtin.copy:
|
||||||
dest: "{{ ssh_keys_file }}"
|
dest: '{{ ssh_keys_file }}'
|
||||||
content: |
|
content: |
|
||||||
{% for key in ssh_public_keys %}
|
{% for key in ssh_public_keys %}
|
||||||
{{ key }}
|
{{ key }}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
mode: '0644'
|
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
|
- name: Create LXC container {{ container_hostname }} with id {{ container_id }} using pct command on shell
|
||||||
ansible.builtin.shell: |
|
ansible.builtin.shell: |
|
||||||
|
set -e
|
||||||
pct create {{ container_id }} {{ container_template }} \
|
pct create {{ container_id }} {{ container_template }} \
|
||||||
-ostype {{ container_ostype }} \
|
-ostype {{ container_ostype }} \
|
||||||
-hostname {{ container_hostname }} \
|
-hostname {{ container_hostname }} \
|
||||||
-password {{ container_password }} \
|
-password '{{ container_password }}' \
|
||||||
-ssh-public-keys {{ ssh_keys_file }} \
|
-ssh-public-keys '{{ ssh_keys_file }}' \
|
||||||
-cores {{ container_cores }} \
|
-cores {{ container_cores }} \
|
||||||
-memory {{ container_memory }} \
|
-memory {{ container_memory }} \
|
||||||
-swap {{ container_swap }} \
|
-swap {{ container_swap }} \
|
||||||
-net0 {{container_net}} \
|
-net0 '{{container_net}}' \
|
||||||
-storage {{ container_storage }} \
|
-storage {{ container_storage }} \
|
||||||
-description "{{ container_description }}" \
|
-description '{{ container_description }}' \
|
||||||
-onboot {{ container_onboot }} \
|
-onboot {{ container_onboot }} \
|
||||||
-protection {{ container_protection }} \
|
-protection {{ container_protection }} \
|
||||||
-unprivileged {{ container_unprivileged }} \
|
-unprivileged {{ container_unprivileged }} \
|
||||||
-tags "{{ container_tags | join(',') }}" \
|
-tags '{{ container_tags | join(',') }}' \
|
||||||
-features {{ container_features }}
|
-features '{{ container_features }}'
|
||||||
args:
|
args:
|
||||||
creates: "/etc/pve/lxc/{{ container_id }}.conf"
|
creates: '/etc/pve/lxc/{{ container_id }}.conf'
|
||||||
no_log: true
|
no_log: false
|
||||||
|
# -password {{ container_password }} \
|
||||||
# -rootfs {{ container_storage }}:{{ container_id }}/vm-{{ container_id }}-disk-0.raw,size=7G \
|
# -rootfs {{ container_storage }}:{{ container_id }}/vm-{{ container_id }}-disk-0.raw,size=7G \
|
||||||
|
|
||||||
# -timezone: {{ localization_timezone }} \
|
# -timezone: {{ localization_timezone }} \
|
||||||
@@ -83,15 +115,15 @@
|
|||||||
- name: Wait until container has an IP address
|
- name: Wait until container has an IP address
|
||||||
ansible.builtin.shell: "pct exec {{ container_id }} -- hostname -I | awk '{print $1}'"
|
ansible.builtin.shell: "pct exec {{ container_id }} -- hostname -I | awk '{print $1}'"
|
||||||
register: lxc_ip
|
register: lxc_ip
|
||||||
until: lxc_ip.stdout != ""
|
until: lxc_ip.stdout != ''
|
||||||
retries: 10
|
retries: 10
|
||||||
delay: 5
|
delay: 5
|
||||||
changed_when: false
|
changed_when: false
|
||||||
failed_when: lxc_ip.stdout == ""
|
failed_when: lxc_ip.stdout == ''
|
||||||
|
|
||||||
- name: Wait for SSH to become available
|
- name: Wait for SSH to become available
|
||||||
ansible.builtin.wait_for:
|
ansible.builtin.wait_for:
|
||||||
host: "{{ lxc_ip.stdout }}"
|
host: '{{ lxc_ip.stdout }}'
|
||||||
port: 22
|
port: 22
|
||||||
delay: 5
|
delay: 5
|
||||||
timeout: 60
|
timeout: 60
|
||||||
@@ -103,18 +135,55 @@
|
|||||||
|
|
||||||
- name: Provision dc1 LXC
|
- name: Provision dc1 LXC
|
||||||
hosts: dc1
|
hosts: dc1
|
||||||
gather_facts: false
|
gather_facts: true
|
||||||
become: true
|
become: true
|
||||||
|
|
||||||
|
# vars:
|
||||||
|
# addc_admin_password: '{{ addc_adminpass }}'
|
||||||
|
|
||||||
tasks:
|
tasks:
|
||||||
|
|
||||||
# - name: Ensure SSH authorized keys are present
|
# - name: Ensure SSH authorized keys are present
|
||||||
# ansible.posix.authorized_key:
|
# ansible.posix.authorized_key:
|
||||||
# user: root
|
# user: root
|
||||||
# key: "{{ item }}"
|
# key: '{{ item }}'
|
||||||
# state: present
|
# 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
|
- name: Install useful packages
|
||||||
ansible.builtin.package:
|
ansible.builtin.package:
|
||||||
@@ -126,18 +195,25 @@
|
|||||||
|
|
||||||
- name: Update all packages, autoclean, and autoremove
|
- name: Update all packages, autoclean, and autoremove
|
||||||
ansible.builtin.apt:
|
ansible.builtin.apt:
|
||||||
name: "*"
|
name: '*'
|
||||||
state: latest
|
state: latest
|
||||||
autoclean: yes
|
autoclean: yes
|
||||||
autoremove: yes
|
autoremove: yes
|
||||||
purge: true
|
purge: true
|
||||||
|
|
||||||
- name: Set timezone to {{ localization_timezone }}
|
- name: Set timezone to {{ localization_timezone }}
|
||||||
community.general.timezone:
|
# community.general.timezone:
|
||||||
name: "{{ localization_timezone }}"
|
timezone:
|
||||||
|
name: '{{ localization_timezone }}'
|
||||||
notify: Restart sshd
|
notify: Restart sshd
|
||||||
tags: [timezone]
|
tags: [timezone]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
- name: Deploy the Samba AD DC role
|
||||||
|
ansible.builtin.include_role:
|
||||||
|
name: ansible_samba_ad_dc
|
||||||
|
|
||||||
# --- Global Handlers ----------------------------------------------
|
# --- Global Handlers ----------------------------------------------
|
||||||
|
|
||||||
handlers:
|
handlers:
|
||||||
|
|||||||
8
vars/debian_template.yml
Normal file
8
vars/debian_template.yml
Normal 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
|
||||||
Reference in New Issue
Block a user