From e350445a4bb6037ba1ef838f2860d0367c57c90c Mon Sep 17 00:00:00 2001 From: Gregor Michels Date: Wed, 14 Sep 2022 02:56:05 +0200 Subject: [PATCH] playbook_provision_hyper01: generify playbook now we read the containers to create dynamically from the inventory --- ansible-inventory | 7 ++++++- playbook_provision_hyper01.yml | 37 +++++++++++++++++++++++----------- 2 files changed, 31 insertions(+), 13 deletions(-) diff --git a/ansible-inventory b/ansible-inventory index c4833bc..a0d628c 100644 --- a/ansible-inventory +++ b/ansible-inventory @@ -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 diff --git a/playbook_provision_hyper01.yml b/playbook_provision_hyper01.yml index 59b8e53..c02bcb0 100644 --- a/playbook_provision_hyper01.yml +++ b/playbook_provision_hyper01.yml @@ -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'] }}"