playbooks

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

commit ce2a792cee49507df76d98fd7077b19a9174f728
parent 670e9c3bea5504dd460e000f3d9e0da84f65612d
Author: pyratebeard <root@pyratebeard.net>
Date:   Thu,  9 May 2024 15:37:49 +0100

homelab | lxc | container_command for user creation. task to create cluster resource. removal tasks

Diffstat:
Mhomelab/lxc/playbook.yml | 35+++++++++++++++++++++++++++++++++++
1 file changed, 35 insertions(+), 0 deletions(-)

diff --git a/homelab/lxc/playbook.yml b/homelab/lxc/playbook.yml @@ -21,6 +21,11 @@ tags: always tasks: + # apt-get install lxc python3-lxc + # /etc/default/lxc-net bridge false + # /etc/lxc/default.conf lxc.net.0.link to virbr0 + # /etc/lxc/lxc.conf lxc.lxcpath to /labfs/ + # mount /labfs with acl option - name: "creation" block: - name: "creation | create container" @@ -30,5 +35,35 @@ template: "{{ lxc_template }}" state: started template_options: "--release {{ lxc_release }}" + container_command: | + useradd -omd /usr/{{ username }} -u 0 -g 0 -s /bin/bash {{ username }} + [ -d /usr/{{ username }}/.ssh ] || mkdir /usr/{{ username }}/.ssh + echo {{ ssh_pub_key }} > /usr/{{ username }}/.ssh/authorized_keys + + - name: "creation | create cluster resource" + ansible.builtin.shell: | + pcs resource create {{ lxc_name }} ocf:heartbeat:lxc \ + container={{ lxc_name }} \ + config=/labfs/{{ lxc_name }}/config \ + op monitor timeout="20s" interval="60s" OCF_CHECK_LEVEL="0" tags: - create + + - name: "removal" + block: + - name: "removal | stop cluster resource" + ansible.builtin.shell: | + pcs resource disable {{ lxc_name }} --wait + + - name: "removal | remove cluster resource" + ansible.builtin.shell: | + pcs resource delete {{ lxc_name }} + + - name: "removal | delete container" + community.general.lxc_container: + name: "{{ lxc_name }}" + container_log: true + state: absent + tags: + - never + - remove