mirror of
https://github.com/dredx/prole.git
synced 2026-09-24 15:04:31 +00:00
53 lines
1.7 KiB
YAML
53 lines
1.7 KiB
YAML
---
|
|
- name: Delete k3s nodes and remove cluster token from vault
|
|
hosts: k3s_hosts
|
|
become: true
|
|
tasks:
|
|
- name: Remove existing k3s installation and data
|
|
ansible.builtin.import_role:
|
|
name: k3s
|
|
tasks_from: cleanup
|
|
|
|
- name: Remove k3s token from Ansible vault
|
|
hosts: localhost
|
|
connection: local
|
|
gather_facts: false
|
|
vars:
|
|
vault_k3s_path: "{{ playbook_dir }}/../inventory/group_vars/all/vault_k3s.yml"
|
|
k3s_vault_password_file: "{{ lookup('env', 'ANSIBLE_VAULT_PASSWORD_FILE') | default('', true) }}"
|
|
tasks:
|
|
- name: Require vault password file for token deletion
|
|
ansible.builtin.assert:
|
|
that:
|
|
- k3s_vault_password_file is defined
|
|
- k3s_vault_password_file | length > 0
|
|
fail_msg: "Set k3s_vault_password_file to a vault password file path."
|
|
|
|
- name: Ensure vault file exists
|
|
ansible.builtin.stat:
|
|
path: "{{ vault_k3s_path }}"
|
|
register: vault_k3s_file
|
|
|
|
- name: Fail when vault file is missing
|
|
ansible.builtin.fail:
|
|
msg: "Vault file not found at {{ vault_k3s_path }}"
|
|
when: not vault_k3s_file.stat.exists
|
|
|
|
- name: Decrypt vault_k3s.yml
|
|
ansible.builtin.command: >-
|
|
ansible-vault decrypt {{ vault_k3s_path }}
|
|
--vault-password-file {{ k3s_vault_password_file }}
|
|
changed_when: true
|
|
|
|
- name: Remove vault_k3s_token entry
|
|
ansible.builtin.lineinfile:
|
|
path: "{{ vault_k3s_path }}"
|
|
regexp: '^vault_k3s_token:'
|
|
state: absent
|
|
|
|
- name: Encrypt vault_k3s.yml
|
|
ansible.builtin.command: >-
|
|
ansible-vault encrypt {{ vault_k3s_path }}
|
|
--vault-password-file {{ k3s_vault_password_file }}
|
|
changed_when: true
|