2025-11-02 08:07:57 +01:00
|
|
|
---
|
|
|
|
|
- name: Create and provision LXC container on Proxmox
|
|
|
|
|
hosts: node0
|
2025-11-01 18:47:03 +01:00
|
|
|
gather_facts: no
|
2025-11-02 08:07:57 +01:00
|
|
|
become: yes
|
|
|
|
|
become_user: root
|
|
|
|
|
|
2025-11-01 18:47:03 +01:00
|
|
|
vars:
|
2025-11-02 08:07:57 +01:00
|
|
|
node_ip: "{{ hostvars['node0']['ansible_host'] }}"
|
2025-11-01 18:47:03 +01:00
|
|
|
addc_hostname: "DC1"
|
|
|
|
|
mac_address: "8E:90:31:DE:31:36"
|
2025-11-02 08:07:57 +01:00
|
|
|
|
|
|
|
|
container_id: 200
|
2025-11-02 08:24:28 +01:00
|
|
|
container_template: "/var/lib/vz/template/cache/debian-13-standard_13.1-1_amd64.tar.zst"
|
2025-11-02 08:20:59 +01:00
|
|
|
container_ostype: debian
|
2025-11-02 08:07:57 +01:00
|
|
|
container_hostname: "{{ addc_hostname }}"
|
2025-11-02 08:36:08 +01:00
|
|
|
container_password: 123456
|
2025-11-02 08:07:57 +01:00
|
|
|
container_storage: local-lvm
|
|
|
|
|
container_rootfs_size: 8G
|
|
|
|
|
container_memory: 1024
|
2025-11-02 08:20:59 +01:00
|
|
|
container_swap: 256
|
2025-11-02 08:07:57 +01:00
|
|
|
container_cores: 2
|
2025-11-02 08:36:08 +01:00
|
|
|
container_net: name=eth0,bridge=vmbr0,ip={{ addc_ansible_host }}/24,gw={{ location_gateway }},hwaddr={{ mac_address }}
|
2025-11-02 08:24:28 +01:00
|
|
|
container_features: "keyctl=1,nesting=1,mount=cifs"
|
2025-11-02 08:27:47 +01:00
|
|
|
container_description: default lxc
|
2025-11-02 08:36:08 +01:00
|
|
|
container_onboot: 1
|
|
|
|
|
container_protection: 0
|
|
|
|
|
container_unprivileged: 1
|
2025-11-02 08:40:18 +01:00
|
|
|
# container_tags: "ansible_managed,test"
|
|
|
|
|
container_tags:
|
|
|
|
|
- ansible_managed
|
|
|
|
|
- test
|
2025-11-02 08:20:59 +01:00
|
|
|
|
2025-11-01 18:47:03 +01:00
|
|
|
|
|
|
|
|
tasks:
|
2025-11-02 08:09:29 +01:00
|
|
|
# - name: Ensure container does not exist
|
2025-11-01 18:47:03 +01:00
|
|
|
|
|
|
|
|
- name: Create LXC container using pct command
|
2025-11-02 08:07:57 +01:00
|
|
|
ansible.builtin.command:
|
|
|
|
|
cmd: >
|
|
|
|
|
pct create 201
|
|
|
|
|
{{ container_template }}
|
2025-11-02 08:36:08 +01:00
|
|
|
--hostname {{ container_hostname }}test
|
2025-11-02 08:07:57 +01:00
|
|
|
--storage {{ container_storage }}
|
|
|
|
|
--memory {{ container_memory }}
|
2025-11-02 08:36:08 +01:00
|
|
|
--cores 1
|
|
|
|
|
--net0 "name=eth0,bridge=vmbr0,ip=dhcp"
|
2025-11-02 08:07:57 +01:00
|
|
|
--unprivileged 1
|
|
|
|
|
--features {{ container_features }}
|
|
|
|
|
--ssh-public-keys /root/.ssh/id_rsa.pub
|
|
|
|
|
args:
|
2025-11-02 08:20:59 +01:00
|
|
|
creates: "/etc/pve/lxc/201.conf"
|
2025-11-02 08:07:57 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- name: Create LXC container using pct command on shell
|
2025-11-02 07:35:28 +01:00
|
|
|
ansible.builtin.shell: |
|
2025-11-02 08:07:57 +01:00
|
|
|
pct create {{ container_id }} {{ container_template }} \
|
2025-11-02 08:20:59 +01:00
|
|
|
-ostype {{ container_ostype }} \
|
2025-11-02 08:07:57 +01:00
|
|
|
-hostname {{ container_hostname }} \
|
2025-11-02 08:36:08 +01:00
|
|
|
-password {{ container_password }} \
|
2025-11-02 08:07:57 +01:00
|
|
|
-cores {{ container_cores }} \
|
|
|
|
|
-memory {{ container_memory }} \
|
2025-11-02 08:20:59 +01:00
|
|
|
-swap {{ container_swap }} \
|
2025-11-02 08:36:08 +01:00
|
|
|
-net0 {{container_net}} \
|
2025-11-02 08:07:57 +01:00
|
|
|
-storage {{ container_storage }} \
|
2025-11-02 08:27:47 +01:00
|
|
|
-description "{{ container_description }}" \
|
2025-11-02 08:36:08 +01:00
|
|
|
-onboot {{ container_onboot }} \
|
|
|
|
|
-protection {{ container_protection }} \
|
|
|
|
|
-unprivileged {{ container_unprivileged }} \
|
2025-11-02 08:40:18 +01:00
|
|
|
-tags "{{ container_tags }}" \
|
2025-11-02 08:07:57 +01:00
|
|
|
-features {{ container_features }}
|
2025-11-02 08:20:59 +01:00
|
|
|
args:
|
|
|
|
|
creates: "/etc/pve/lxc/{{ container_id }}.conf"
|
|
|
|
|
|
2025-11-02 08:07:57 +01:00
|
|
|
# -timezone: {{ localization_timezone }} \
|