Browse Source

roles/lxc_guest: add support for alpine linux vm

python3
Zolfa 4 years ago
parent
commit
48a365730f
Signed by: zolfa GPG Key ID: E1A43B038C4D6616
3 changed files with 34 additions and 5 deletions
  1. +2
    -1
      roles/lxc_guest/defaults/main.yaml
  2. +30
    -4
      roles/lxc_guest/tasks/main.yaml
  3. +2
    -0
      roles/lxc_guest/templates/config.j2

+ 2
- 1
roles/lxc_guest/defaults/main.yaml View File

@ -1,7 +1,8 @@
---
auto_start: true
container_state: 'started'
distro: 'buster'
distro: 'debian'
release: 'bullseye'
vm_size: '5G'
vg_name: '{{ hostvars[ansible_lxc_host]["vg_name"] | default(ansible_lxc_host+"-vg") }}'
host_fqdn: '{{ inventory_hostname }}.dmz.{{ domain }}'


+ 30
- 4
roles/lxc_guest/tasks/main.yaml View File

@ -15,8 +15,9 @@
- name: 'check if release is supported'
assert:
that: distro in [ 'bullseye', 'sid', 'buster' ]
msg: 'release {{ distro }} not supported by debian template'
that: release in [ 'bullseye', 'sid', 'buster' ]
msg: 'release {{ release }} not supported by debian template'
when: distro == 'debian'
tags:
- 'lxc'
@ -37,7 +38,7 @@
# leaking when lvm is invoked
environment:
LVM_SUPPRESS_FD_WARNINGS: 1
when: not unprivileged
when: (not unprivileged) and distro == 'debian'
- name: 'unprivileged | upload bash script'
copy:
@ -83,7 +84,7 @@
lv_name: 'vm_{{ vm_name }}'
container_log: true
template: 'download'
template_options: '-d debian -r {{ distro }} -a amd64'
template_options: '-d {{ distro }} -r {{ release }} -a amd64'
config: '/tmp/lxc_unpriv_config'
state: 'stopped'
when: unprivileged
@ -93,6 +94,30 @@
src: 'config.j2'
dest: '/var/lib/lxc/{{ vm_name }}/config'
- block:
- name: 'unprivilaged | alpine | start for tweak'
lxc_container:
name: '{{ vm_name }}'
state: 'restarted'
- name: 'unprivileged | alpine | tweak'
raw: |
rm /etc/network/interfaces
echo 'nameserver {{ hostvars | ip_from_inventory('vm_gateway') }}' > /etc/resolv.conf
delegate_to: '{{ vm_name }}'
connection: 'ssh_lxc'
- name: 'unprivileged | alpine | restart'
lxc_container:
name: '{{ vm_name }}'
state: 'restarted'
- name: 'unprivileged | alpine | install python'
raw: |
apk update
apk upgrade
apk add python3
delegate_to: '{{ vm_name }}'
connection: 'ssh_lxc'
when: distro == 'alpine'
- name: 'unprivileged | tweak config'
lxc_container:
name: '{{ vm_name }}'
@ -167,6 +192,7 @@
- { key: 'APT::Periodic::Update-Package-Lists', value: '1' }
- { key: 'APT::Periodic::Verbose', value: '2' }
delegate_to: '{{ vm_name }}'
when: distro == 'debian'
connection: 'ssh_lxc'
- meta: 'flush_handlers'


+ 2
- 0
roles/lxc_guest/templates/config.j2 View File

@ -4,10 +4,12 @@ lxc.include = /usr/share/lxc/config/common.conf
lxc.include = /usr/share/lxc/config/userns.conf
lxc.arch = linux64
{% if distro == 'debian' %}
lxc.mount.entry = /sys/kernel/debug sys/kernel/debug none bind,optional 0 0
lxc.mount.entry = /sys/kernel/security sys/kernel/security none bind,optional 0 0
lxc.mount.entry = /sys/fs/pstore sys/fs/pstore none bind,optional 0 0
lxc.mount.entry = mqueue dev/mqueue mqueue rw,relatime,create=dir,optional 0 0
{% endif %}
lxc.apparmor.profile = generated


Loading…
Cancel
Save