playbooks

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

playbook.yml (2334B)


      1 ---
      2 #   ██
      3 #  ░██
      4 #  ░██ ██   ██  █████
      5 #  ░██░░██ ██  ██░░░██
      6 #  ░██ ░░███  ░██  ░░
      7 #  ░██  ██░██ ░██   ██
      8 #  ███ ██ ░░██░░█████
      9 # ░░░ ░░   ░░  ░░░░░
     10 #
     11 #  author ▓▒ pyratebeard <root@pyratebeard.net>
     12 #    code ▓▒ https://git.pyratebeard.net/playbooks/
     13 
     14 - hosts: pigley
     15   gather_facts: true
     16   become: true
     17   pre_tasks:
     18     - name: "load vars"
     19       ansible.builtin.include_vars:
     20         file: vars.yml
     21       tags: always
     22 
     23   tasks:
     24   # apt-get install lxc python3-lxc
     25   # /etc/default/lxc-net bridge false
     26   # /etc/lxc/default.conf lxc.net.0.link to virbr0
     27   # /etc/lxc/lxc.conf lxc.lxcpath to /labfs/
     28   # mount /labfs with acl option
     29     - name: "creation"
     30       block:
     31         - name: "creation | create container"
     32           community.general.lxc_container:
     33             name: "{{ lxc_name }}"
     34             container_log: true
     35             template: "{{ lxc_template }}"
     36             state: started
     37             template_options: "--release {{ lxc_release }}"
     38             container_command: |
     39               useradd -omd /usr/{{ username }} -u 0 -g 0 -s /bin/bash {{ username }}
     40               [ -d /usr/{{ username }}/.ssh ] || mkdir /usr/{{ username }}/.ssh
     41               echo {{ ssh_pub_key }} > /usr/{{ username }}/.ssh/authorized_keys
     42 
     43         - name: "creation | create cluster resource"
     44           ansible.builtin.shell: |
     45             pcs resource create {{ lxc_name }} ocf:heartbeat:lxc \
     46             container={{ lxc_name }} \
     47             config=/labfs/{{ lxc_name }}/config \
     48             op monitor timeout="20s" interval="60s" OCF_CHECK_LEVEL="0"
     49           tags: create-resource
     50       tags:
     51         - create
     52 
     53     - name: "removal"
     54       block:
     55         - name: "removal | stop cluster resource"
     56           ansible.builtin.shell: |
     57             pcs resource disable {{ lxc_name }} --wait
     58 
     59         - name: "removal | remove cluster resource"
     60           ansible.builtin.shell: |
     61               pcs resource delete {{ lxc_name }}
     62 
     63         - name: "removal | delete container"
     64           community.general.lxc_container:
     65             name: "{{ lxc_name }}"
     66             container_log: true
     67             state: absent
     68       tags:
     69         - never
     70         - remove