@ -11,7 +11,7 @@
- name : Check debian release
- name : Check debian release
assert:
assert:
that : distro in [ 'stretch ', 'sid', 'buster' ]
that : distro in [ 'bullseye ', 'sid', 'buster' ]
msg : "release {{ distro }} not supported by debian template"
msg : "release {{ distro }} not supported by debian template"
- block:
- block:
@ -20,12 +20,12 @@
name : "{{ vm_name }}"
name : "{{ vm_name }}"
backing_store : lvm
backing_store : lvm
fs_size : "{{ vm_size }}"
fs_size : "{{ vm_size }}"
vg_name : "{{ inventory_hostname }}vg "
vg_name : "{{ vg_name | default( inventory_hostname+'vg') }}"
lv_name : "vm_{{ vm_name }}"
lv_name : "vm_{{ vm_name }}"
fs_type : xfs
fs_type : ext4
container_log : true
container_log : true
template : debian
template : debian
template_options : --release {{ distro }} --packages=ssh,python
template_options : --release {{ distro }} --packages=ssh,python3
state : stopped
state : stopped
# suppress messages related to file descriptors
# suppress messages related to file descriptors
# leaking when lvm is invoked
# leaking when lvm is invoked
@ -58,30 +58,39 @@
register : container_running_state
register : container_running_state
- name : Read container DNS configuration
- name : Read container DNS configuration
container_file_read:
name : "{{ vm_name }}"
path : /etc/resolv.conf
slurp:
src : /etc/resolv.conf
delegate_to : "{{ vm_name }}"
connection : ssh_lxc
register : vm_resolv_conf
register : vm_resolv_conf
- debug:
- debug:
var : vm_resolv_conf
msg : "{{ vm_resolv_conf['content'] | b64decode }}"
verbosity : 2
verbosity : 2
- name : update container DNS configuration
- name : update container DNS configuration
shell : lxc-attach -n {{ vm_name }} --clear-env -e -- bash -c "grep -Pz1 'domain lilik.it\nnameserver {{ hostvars | ip_from_inventory('vm_gateway') }}' /etc/resolv.conf || echo -e 'domain lilik.it\nnameserver {{ hostvars | ip_from_inventory('vm_gateway') }}' > /etc/resolv.conf"
register : container_dns_configuration
changed_when : container_dns_configuration.stdout != "domain lilik.it\nnameserver {{ hostvars | ip_from_inventory('vm_gateway') }}\n\u0000"
template:
src : resolv.conf.j2
dest : /etc/resolv.conf
delegate_to : "{{ vm_name }}"
connection : ssh_lxc
- name : update container network configuration
- name : update container network configuration
shell : lxc-attach -n {{ vm_name }} --clear-env -e -- bash -c "grep -F 'iface eth0 inet manual' /etc/network/interfaces || sed -i 's/iface eth0 inet dhcp/iface eth0 inet manual/' /etc/network/interfaces"
register : container_network
changed_when : "container_network.stdout != 'iface eth0 inet manual'"
copy:
src : interfaces
dest : /etc/network/interfaces
delegate_to : "{{ vm_name }}"
connection : ssh_lxc
notify : restart container
notify : restart container
- name : install packages
- name : install packages
shell : lxc-attach -n {{ vm_name }} --clear-env -e -- bash -c "apt-get update && apt-get install python ssh -y"
register : install_packages
changed_when : "install_packages.stdout.find('0 newly installed') == -1"
apt:
pkg:
- python3
- ssh
state : present
update_cache : yes
cache_valid_time : 3600
notify : restart container
notify : restart container
# Restart container when one in
# Restart container when one in
@ -94,6 +103,6 @@
- name : add monitoring facts
- name : add monitoring facts
set_fact:
set_fact:
monitoring_host : "{{monitoring_host| default([]) }} + [ '{{ vm_name }}' ]"
monitoring_host : "{{ monitoring_host | default([]) }} + [ '{{ vm_name }}' ]"
delegate_facts : True
delegate_facts : True
delegate_to : status
delegate_to : status