playbooks

ansible config management
git clone git://git.pyratebeard.net/playbooks.git
Log | Files | Refs | README

commit eb04a6f040a47121819504b533135028eab170bf
parent ce2a792cee49507df76d98fd7077b19a9174f728
Author: pyratebeard <root@pyratebeard.net>
Date:   Fri, 10 May 2024 23:31:33 +0100

homelab | libvirt | terraform works on localhost now

Diffstat:
Mhomelab/libvirt/playbook.yml | 102++++++++++++++++++++++---------------------------------------------------------
Mhomelab/libvirt/vars.yml | 12++++++------
Ahomelab/lxc/vars.yml | 6++++++
3 files changed, 40 insertions(+), 80 deletions(-)

diff --git a/homelab/libvirt/playbook.yml b/homelab/libvirt/playbook.yml @@ -27,32 +27,19 @@ check_mode: false failed_when: false tags: always + delegate_to: localhost # ▓▒ start of block ▒▓ - name: "prepare" block: - name: "prepare | install pre-reqs" - ansible.builtin.apt: - pkg: - - gnupg - - software-properties-common - - genisoimage - update_cache: true - - - name: "prepare | download hashicorp gpg key" - ansible.builtin.shell: wget -O- https://apt.releases.hashicorp.com/gpg | gpg --dearmor | tee /usr/share/keyrings/hashicorp-archive-keyring.gpg >/dev/null - - - name: "prepare | add hashicorp repo" - ansible.builtin.apt_repository: - repo: "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com {{ ansible_distribution_release }} main" + ansible.builtin.pacman: + name: + #- tofu (aur package) + - cdrtools state: present - - name: "prepare | install terraform" - ansible.builtin.apt: - name: terraform - update_cache: true - - name: "prepare | disable security for libvirt" ansible.builtin.lineinfile: path: "/etc/libvirt/qemu.conf" @@ -61,20 +48,14 @@ notify: restart libvirtd when: command.rc != 0 + delegate_to: localhost # ▓▒ end of block ▒▓ - - name: "upload project_files" - ansible.builtin.copy: - src: "{{ terraform_project }}" - dest: "{{ project_files }}" - check_mode: false - tags: upload - - name: "creation" block: - name: "creation | create vm" community.general.terraform: - project_path: '{{ project_files }}' + project_path: '{{ tofu_project }}' state: present complex_vars: true variables: @@ -83,6 +64,7 @@ vm_mem: "{{ vm_mem }}" vm_size: "{{ vm_size }}" force_init: true + delegate_to: localhost - name: "creation | shutdown vm & dumpxml" ansible.builtin.shell: | @@ -98,25 +80,28 @@ allow-migrate=true rescue: - - name: "creation rescue | shutdown vm" + - name: "rescue | stop cluster resource" ansible.builtin.shell: | - virsh list --all | grep {{ vm_name }} | grep "shut off" >/dev/null || \ - virsh destroy {{ vm_name }} + pcs resource disable {{ vm_name }} --wait failed_when: false - - name: "creation rescue | undefine vm" + - name: "rescue | remove cluster resource" ansible.builtin.shell: | - virsh undefine {{ vm_name }} + pcs resource delete {{ vm_name }} + failed_when: false + + - name: "rescue | destroy vm" + community.general.terraform: + project_path: '{{ tofu_project }}' + state: absent + delegate_to: localhost failed_when: false - - name: "creation rescue | remove vm files" + - name: "removal | tidy up vm files" ansible.builtin.file: - path: "/labfs/{{ vm_name }}.{{ item }}" + path: "/labfs/{{ vm_name }}.xml" state: absent failed_when: false - with_items: - - qcow2 - - xml tags: - create @@ -130,52 +115,21 @@ ansible.builtin.shell: | pcs resource delete {{ vm_name }} - - name: "removal | undefine domain" - ansible.builtin.shell: | - virsh undefine {{ vm_name }} + - name: "removal | destroy vm" + community.general.terraform: + project_path: '{{ tofu_project }}' + state: absent + delegate_to: localhost - - name: "removal | remove vm files" + - name: "removal | tidy up vm files" ansible.builtin.file: - path: "/labfs/{{ vm_name }}.{{ item }}" + path: "/labfs/{{ vm_name }}.xml" state: absent - with_items: - - qcow2 - - xml tags: - never - remove - destroy - - name: "cleanup" - block: - - name: "cleanup | remove project files" - ansible.builtin.file: - path: "{{ project_files }}" - state: absent - check_mode: false - - - name: "cleanup | remove cloud-init iso" - ansible.builtin.file: - path: "/labfs/commoninit.iso" - state: absent - check_mode: false - - - name: "cleanup | find tfplan files" - ansible.builtin.find: - paths: "/tmp/" - patterns: "tmp.*tfplan$" - use_regex: true - register: tfplan_files - check_mode: false - - - name: "cleanup | tidy up tfplan files" - ansible.builtin.file: - path: "{{ item }}" - state: absent - loop: "{{ tfplan_files.files|map(attribute='path')|list }}" - check_mode: false - tags: always - handlers: - name: "restart libvirtd" ansible.builtin.service: diff --git a/homelab/libvirt/vars.yml b/homelab/libvirt/vars.yml @@ -1,10 +1,10 @@ ## modify for vm creation -vm_os: "debian12" # shortname as used in terraform dir -vm_name: "vm-{{ vm_os }}" -vm_vcpus: "2" -vm_mem: "2048" +vm_os: "debian12" # shortname as used in opentofu dir +#vm_name: "vm-{{ vm_os }}" +vm_name: "vm-webpage" +vm_vcpus: "1" +vm_mem: "1024" vm_size: "8589934592" # 8G #vm_size: "21474836480" # 20G -terraform_project: "~src/infra_code/libvirt/{{ vm_os }}/" -project_files: "/tmp/terraform_project_files" +tofu_project: "~src/infra_code/libvirt/{{ vm_os }}/" diff --git a/homelab/lxc/vars.yml b/homelab/lxc/vars.yml @@ -0,0 +1,6 @@ +lxc_template: "debian" +lxc_release: "bookworm" +lxc_name: "lxc-{{ lxc_template }}" +username: "dwarf" +ssh_pub_key: "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAICSluiY54h5FlGxnnXqifWPnfvKNIh1/f0xf0yCThdqV" +