Ansible. Proxmox. Create Container Almalinux 8 from template using Ansible Playbook
Перейти к навигации
Перейти к поиску
PVE server
Download CT template
pveam available
pveam download cephfs01-pve almalinux-8-default_20210928_amd64.tar.xz
Ansible server
Install ansible
dnf install -y ansible
Create root Ansible project dir
mkdir ./pve_create_ct
cd ./pve_create_ct
Add necessary project files
tree
. ├── ansible.cfg ├── ct_create.yml ├── inventory │ └── hosts.ini └── vars.yml
mkdir ./inventory
nano inventory/hosts.ini
[pve]
pve01 ansible_port=22 ansible_host=192.168.17.251 ansible_host_ip=192.168.17.251
[pve:vars]
ansible_user=root
ansible_ssh_pass=PassWord
nano ansible.cfg
[defaults]
inventory = inventory/hosts.ini
host_key_checking = False
stdout_callback = yaml
callback_enabled = timer
nano vars.yml
pve_api_host: 192.168.17.251
pve_api_user: root@pam
pve_api_password: PassWord#1
pve_node: pve01
ct_id: 501
ct_storage: ceph-rbd01
ct_password: PassWord
ct_hostname: ct-al8-autodeploy-01
ct_unprivileged: true
ct_ostemplate: cephfs01-pve:vztmpl/almalinux-8-default_20210928_amd64.tar.xz
ct_cores: 1
ct_memory: 512
ct_swap: 512
ct_disk: 5
ct_onboot: yes
ct_netif: '{"net0":"name=eth0,ip=dhcp,bridge=vmbr0"}'
nano ct_create.yml
---
- name: Initial setup LXC
hosts: pve01
vars_files:
- vars.yml
tasks:
- name: Create LXC
proxmox:
timeout: 3600
node: "{{ pve_node }}"
api_user: "{{ pve_api_user }}"
api_password: "{{ pve_api_password }}"
api_host: "{{ pve_api_host }}"
hostname: "{{ ct_hostname }}"
#vmid: "{{ ct_id }}"
storage: "{{ ct_storage }}"
password: "{{ ct_password }}"
unprivileged: "{{ ct_unprivileged }}"
ostemplate: "{{ ct_ostemplate }}"
cores: "{{ ct_cores }}"
memory: "{{ ct_memory }}"
swap: "{{ ct_swap }}"
disk: "{{ ct_disk }}"
onboot: "{{ ct_onboot }}"
netif: "{{ ct_netif }}"
- name: Start LXC
tags:
- start-lxc
proxmox:
api_host: "{{ pve_api_host }}"
api_password: "{{ pve_api_password }}"
api_user: "{{ pve_api_user }}"
hostname: "{{ ct_hostname }}"
#vmid: "{{ ct_id }}"
node: "{{ pve_node }}"
state: started
...
Edit vars
nano inventory/hosts.ini
nano vars.ini
Run VM creation
ansible-playbook ct_create.yml