Playbooks to a new Lilik
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

92 lines
2.2 KiB

---
- name: 'check if container dir exists'
stat:
path: '/var/lib/lxc/{{ vm_name }}'
register: container_dir
tags:
- 'lxc'
- name: 'check if container exists'
container_exists:
name: '{{ vm_name }}'
register: container_exists
tags:
- 'lxc'
- name: 'check if release is supported'
assert:
that: distro in [ 'bullseye', 'sid', 'buster' ]
msg: 'release {{ distro }} not supported by debian template'
tags:
- 'lxc'
- block:
- name: 'create the lxc container'
lxc_container:
name: '{{ vm_name }}'
backing_store: 'lvm'
fs_size: '{{ vm_size }}'
vg_name: '{{ vg_name }}'
lv_name: 'vm_{{ vm_name }}'
fs_type: 'xfs'
container_log: true
template: 'debian'
template_options: '--release {{ distro }} --packages=ssh,python3,python3-apt'
state: 'stopped'
# suppress messages related to file descriptors
# leaking when lvm is invoked
environment:
LVM_SUPPRESS_FD_WARNINGS: 1
- name: 'deploy container config'
template:
src: 'config.j2'
dest: '/var/lib/lxc/{{ vm_name }}/config'
- name: 'start container'
lxc_container:
name: '{{ vm_name }}'
state: 'started'
when: auto_start|bool
when: not (container_exists.exists and container_dir.stat.isdir)
tags:
- 'lxc'
- name: 'update container config'
template:
src: 'config.j2'
dest: '/var/lib/lxc/{{ vm_name }}/config'
register: container_config
notify: 'restart container'
- name: 'set container running state'
lxc_container:
name: '{{ vm_name }}'
state: '{{ container_state }}'
register: container_running_state
tags:
- 'lxc'
- name: 'update container resolv.conf'
template:
src: 'resolv.conf.j2'
dest: '/etc/resolv.conf'
delegate_to: '{{ vm_name }}'
connection: 'ssh_lxc'
- name: 'update container net config'
copy:
src: 'interfaces'
dest: '/etc/network/interfaces'
delegate_to: '{{ vm_name }}'
connection: 'ssh_lxc'
notify: 'restart container'
- meta: 'flush_handlers'
- name: 'add monitoring facts'
set_fact:
monitoring_host: '{{ monitoring_host | default([]) }} + [ "{{ vm_name }}" ]'
delegate_facts: true
delegate_to: 'status'
...