playbook_provision_hyper01: generify playbook

now we read the containers to create dynamically from the inventory
This commit is contained in:
Gregor Michels 2022-09-14 02:56:05 +02:00
parent 24a31603ef
commit e350445a4b
2 changed files with 31 additions and 13 deletions

View File

@ -19,4 +19,9 @@ hyper01 ip=10.84.1.21
[vms]
eae-adp-jump01 ip=162.55.53.85 monitoring_ip=10.84.254.0 ansible_python_interpreter=/usr/local/bin/python3
monitoring01 ip=10.84.1.51
[container]
monitoring01 ip=10.84.1.51 cpus=2 disk=50 memory=1024 net='{"net0":"name=eth0,ip=10.84.1.51/24,gw=10.84.1.1,bridge=vmbr0"}'
[container:vars]
ostemplate=local:vztmpl/debian-11-standard_11.3-1_amd64.tar.zst

View File

@ -1,25 +1,38 @@
---
- name: create vms/container
- name: provision containers
hosts: 127.0.0.1
connection: local
gather_facts: no
vars:
proxmox_host: "hyper01"
tasks:
- name: create monitoring01
- name: create containers
proxmox:
api_user: root@pam
api_password: "{{ lookup('passwordstore', 'server/hyper01') }}"
api_host: "{{ hostvars['hyper01']['ip'] }}"
node: hyper01
hostname: monitoring01
api_password: "{{ lookup('passwordstore', 'server/{{ proxmox_host }}') }}"
api_host: "{{ hostvars[proxmox_host]['ip'] }}"
node: "{{ proxmox_host }}"
hostname: "{{ item }}"
onboot: yes
cpus: 2
disk: 50
memory: 1024
cpus: "{{ hostvars[item]['cpus'] }}"
disk: "{{ hostvars[item]['disk'] }}"
memory: "{{ hostvars[item]['memory'] }}"
storage: 'local-zfs'
ostemplate: 'local:vztmpl/debian-11-standard_11.3-1_amd64.tar.zst'
password: "{{ lookup('passwordstore', 'vms/monitoring01/root') }}"
ostemplate: "{{ hostvars[item]['ostemplate'] }}"
password: "{{ lookup('passwordstore', 'vms/{{ item }}/root') }}"
pubkey: "{{ lookup('ansible.builtin.file', 'files/authorized_keys') }}"
netif: '{"net0":"name=eth0,ip=10.84.1.51/24,gw=10.84.1.1,bridge=vmbr0"}'
netif: "{{ hostvars[item]['net'] }}"
unprivileged: yes
features:
- nesting=1
with_items: "{{ groups['container'] }}"
- name: start containers
proxmox:
api_user: root@pam
api_password: "{{ lookup('passwordstore', 'server/{{ proxmox_host }}') }}"
api_host: "{{ hostvars[proxmox_host]['ip'] }}"
node: "{{ proxmox_host }}"
hostname: "{{ item }}"
state: started
with_items: "{{ groups['container'] }}"