|
11 | 11 |
|
12 | 12 | - name: Check debian release |
13 | 13 | assert: |
14 | | - that: distro in [ 'stretch', 'sid', 'buster' ] |
| 14 | + that: distro in [ 'bullseye', 'sid', 'buster' ] |
15 | 15 | msg: "release {{ distro }} not supported by debian template" |
16 | 16 |
|
17 | 17 | - block: |
|
20 | 20 | name: "{{ vm_name }}" |
21 | 21 | backing_store: lvm |
22 | 22 | fs_size: "{{ vm_size }}" |
23 | | - vg_name: "{{ inventory_hostname }}vg" |
| 23 | + vg_name: "{{ vg_name | default(inventory_hostname+'vg') }}" |
24 | 24 | lv_name: "vm_{{ vm_name }}" |
25 | | - fs_type: xfs |
| 25 | + fs_type: ext4 |
26 | 26 | container_log: true |
27 | 27 | template: debian |
28 | | - template_options: --release {{ distro }} --packages=ssh,python |
| 28 | + template_options: --release {{ distro }} --packages=ssh,python3 |
29 | 29 | state: stopped |
30 | 30 | # suppress messages related to file descriptors |
31 | 31 | # leaking when lvm is invoked |
|
58 | 58 | register: container_running_state |
59 | 59 |
|
60 | 60 | - name: Read container DNS configuration |
61 | | - container_file_read: |
62 | | - name: "{{ vm_name }}" |
63 | | - path: /etc/resolv.conf |
| 61 | + slurp: |
| 62 | + src: /etc/resolv.conf |
| 63 | + delegate_to: "{{ vm_name }}" |
| 64 | + connection: ssh_lxc |
64 | 65 | register: vm_resolv_conf |
65 | 66 |
|
66 | 67 | - debug: |
67 | | - var: vm_resolv_conf |
| 68 | + msg: "{{ vm_resolv_conf['content'] | b64decode }}" |
68 | 69 | verbosity: 2 |
69 | 70 |
|
70 | 71 | - name: update container DNS configuration |
71 | | - 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" |
72 | | - register: container_dns_configuration |
73 | | - changed_when: container_dns_configuration.stdout != "domain lilik.it\nnameserver {{ hostvars | ip_from_inventory('vm_gateway') }}\n\u0000" |
| 72 | + template: |
| 73 | + src: resolv.conf.j2 |
| 74 | + dest: /etc/resolv.conf |
| 75 | + delegate_to: "{{ vm_name }}" |
| 76 | + connection: ssh_lxc |
74 | 77 |
|
75 | 78 | - name: update container network configuration |
76 | | - 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" |
77 | | - register: container_network |
78 | | - changed_when: "container_network.stdout != 'iface eth0 inet manual'" |
| 79 | + copy: |
| 80 | + src: interfaces |
| 81 | + dest: /etc/network/interfaces |
| 82 | + delegate_to: "{{ vm_name }}" |
| 83 | + connection: ssh_lxc |
79 | 84 | notify: restart container |
80 | 85 |
|
81 | 86 | - name: install packages |
82 | | - shell: lxc-attach -n {{ vm_name }} --clear-env -e -- bash -c "apt-get update && apt-get install python ssh -y" |
83 | | - register: install_packages |
84 | | - changed_when: "install_packages.stdout.find('0 newly installed') == -1" |
| 87 | + apt: |
| 88 | + pkg: |
| 89 | + - python3 |
| 90 | + - ssh |
| 91 | + state: present |
| 92 | + update_cache: yes |
| 93 | + cache_valid_time: 3600 |
85 | 94 | notify: restart container |
86 | 95 |
|
87 | 96 | # Restart container when one in |
|
94 | 103 |
|
95 | 104 | - name: add monitoring facts |
96 | 105 | set_fact: |
97 | | - monitoring_host: "{{monitoring_host| default([]) }} + [ '{{ vm_name }}' ]" |
| 106 | + monitoring_host: "{{ monitoring_host | default([]) }} + [ '{{ vm_name }}' ]" |
98 | 107 | delegate_facts: True |
99 | 108 | delegate_to: status |
0 commit comments