From 013e945d2d91d067f450594a319e851b6b356aa5 Mon Sep 17 00:00:00 2001 From: "Daniel A. Maierhofer" Date: Fri, 16 Mar 2018 17:53:25 +0100 Subject: [PATCH] Improve lxc config --- group_vars/{ariane => fet_hosts} | 0 host_vars/ariane | 12 ++++++++++++ hosts/production | 2 +- roles/ariane/files/lxc-zyklon.conf | 15 --------------- roles/ariane/tasks/lxc-betam.yml | 14 -------------- roles/ariane/tasks/lxc-zyklon.yml | 14 -------------- roles/ariane/tasks/lxc.yml | 16 ++++++++++++++++ roles/ariane/tasks/main.yml | 8 -------- roles/ariane/templates/lxc-betam.conf.j2 | 24 ------------------------ roles/ariane/templates/lxc.j2 | 12 +++++++----- site.yml | 6 +++++- 11 files changed, 41 insertions(+), 82 deletions(-) rename group_vars/{ariane => fet_hosts} (100%) delete mode 100644 roles/ariane/files/lxc-zyklon.conf delete mode 100644 roles/ariane/tasks/lxc-betam.yml delete mode 100644 roles/ariane/tasks/lxc-zyklon.yml delete mode 100644 roles/ariane/templates/lxc-betam.conf.j2 diff --git a/group_vars/ariane b/group_vars/fet_hosts similarity index 100% rename from group_vars/ariane rename to group_vars/fet_hosts diff --git a/host_vars/ariane b/host_vars/ariane index ddf8362..8081c3d 100644 --- a/host_vars/ariane +++ b/host_vars/ariane @@ -1,2 +1,14 @@ inventory_hostname: ariane.fet.htu.tuwien.ac.at inventory_hostname_short: ariane + +lxc: + containers: + - name: betam + revision: "01" + hwaddr: 2e:6d:b6:07:14:01 + template: debian + extra: lxc.cgroup.devices.allow = c 188:0 rwm + - name: zyklon + revision: "01" + hwaddr: 2e:6d:b6:07:15:01 + template: voidlinux diff --git a/hosts/production b/hosts/production index 7c2a76d..2405809 100644 --- a/hosts/production +++ b/hosts/production @@ -1,6 +1,6 @@ all: children: - fet: + fet_hosts: hosts: ariane: lxc-pet-01: diff --git a/roles/ariane/files/lxc-zyklon.conf b/roles/ariane/files/lxc-zyklon.conf deleted file mode 100644 index 092ffb6..0000000 --- a/roles/ariane/files/lxc-zyklon.conf +++ /dev/null @@ -1,15 +0,0 @@ -# {{ ansible_managed }} - -lxc.network.type = veth -lxc.network.link = br0 -lxc.network.flags = up -lxc.network.hwaddr = 2e:6d:b6:07:15:01 - -lxc.aa_profile = unconfined -lxc.rootfs = /var/lib/lxc/lxc-zyklon-01/rootfs -lxc.rootfs.backend = dir - -lxc.include = /usr/share/lxc/config/voidlinux.common.conf - -lxc.utsname = lxc-zyklon-01 -lxc.arch = amd64 diff --git a/roles/ariane/tasks/lxc-betam.yml b/roles/ariane/tasks/lxc-betam.yml deleted file mode 100644 index d20acd9..0000000 --- a/roles/ariane/tasks/lxc-betam.yml +++ /dev/null @@ -1,14 +0,0 @@ ---- -- name: lxc - betam container - lxc_container: - name: lxc-betam-01 - template: debian - -- name: lxc - betam config - template: - dest: /var/lib/lxc/lxc-betam-01/config - src: lxc-betam.conf.j2 - owner: root - group: root - mode: 0644 - backup: yes diff --git a/roles/ariane/tasks/lxc-zyklon.yml b/roles/ariane/tasks/lxc-zyklon.yml deleted file mode 100644 index 709b26b..0000000 --- a/roles/ariane/tasks/lxc-zyklon.yml +++ /dev/null @@ -1,14 +0,0 @@ ---- -- name: lxc - zyklon container - lxc_container: - name: lxc-zyklon-01 - template: voidlinux - -- name: lxc - zyklon config - copy: - dest: /var/lib/lxc/lxc-zyklon-01/config - src: lxc-zyklon.conf - owner: root - group: root - mode: 0644 - backup: yes diff --git a/roles/ariane/tasks/lxc.yml b/roles/ariane/tasks/lxc.yml index 801a0bd..728abf0 100644 --- a/roles/ariane/tasks/lxc.yml +++ b/roles/ariane/tasks/lxc.yml @@ -28,3 +28,19 @@ group: root mode: 0644 backup: yes + +- name: lxc - create container + lxc_container: + name: "lxc-{{ item.name }}-{{ item.revision }}" + template: "{{ item.template }}" + with_items: "{{ lxc.containers }}" + +- name: lxc - config + template: + dest: "/var/lib/lxc/lxc-{{ item.name }}-{{ item.revision }}/config" + src: lxc.j2 + owner: root + group: root + mode: 0644 + backup: yes + with_items: "{{ lxc.containers }}" diff --git a/roles/ariane/tasks/main.yml b/roles/ariane/tasks/main.yml index 4988654..f5b0b9b 100644 --- a/roles/ariane/tasks/main.yml +++ b/roles/ariane/tasks/main.yml @@ -23,14 +23,6 @@ when: ariane_lxc tags: ['ariane_lxc', 'lxc'] -- include_tasks: lxc-betam.yml - when: ariane_lxc - tags: ['ariane_lxc', 'lxc'] - -- include_tasks: lxc-zyklon.yml - when: ariane_lxc - tags: ['ariane_lxc', 'lxc'] - - include_tasks: snapper.yml when: ariane_snapper tags: ['ariane_snapper', 'snapper'] diff --git a/roles/ariane/templates/lxc-betam.conf.j2 b/roles/ariane/templates/lxc-betam.conf.j2 deleted file mode 100644 index 49ca8c0..0000000 --- a/roles/ariane/templates/lxc-betam.conf.j2 +++ /dev/null @@ -1,24 +0,0 @@ -# {{ ansible_managed }} - -lxc.network.type = veth -lxc.network.link = br0 -lxc.network.flags = up -lxc.network.hwaddr = 2e:6d:b6:07:14:01 - -lxc.aa_profile = unconfined -lxc.rootfs = /var/lib/lxc/lxc-{{ lxc_host }}-01/rootfs -lxc.rootfs.backend = dir - -lxc.include = /usr/share/lxc/config/debian.common.conf - -lxc.utsname = lxc-betam-01 -lxc.arch = amd64 - -lxc.cgroup.devices.allow = c 188:0 rwm - - -lxc_host: betam -lxc_rev: 01 -lxc_hwaddr: 2e:6d:b6:07:14:01 -lxc_extra: lxc.cgroup.devices.allow = c 188:0 rwm - diff --git a/roles/ariane/templates/lxc.j2 b/roles/ariane/templates/lxc.j2 index 9185b1f..c2660b1 100644 --- a/roles/ariane/templates/lxc.j2 +++ b/roles/ariane/templates/lxc.j2 @@ -3,15 +3,17 @@ lxc.network.type = veth lxc.network.link = br0 lxc.network.flags = up -lxc.network.hwaddr = {{ lxc_hwaddr }} +lxc.network.hwaddr = {{ item.hwaddr }} lxc.aa_profile = unconfined -lxc.rootfs = /var/lib/lxc/lxc-{{ lxc_host }}-{{ lxc_rev }}/rootfs +lxc.rootfs = /var/lib/lxc/lxc-{{ item.name }}-{{ item.revision }}/rootfs lxc.rootfs.backend = dir -lxc.include = /usr/share/lxc/config/debian.common.conf +lxc.include = /usr/share/lxc/config/{{ item.template }}.common.conf -lxc.utsname = lxc-{{ lxc_host }}-{{ lxc-rev }} +lxc.utsname = lxc-{{ item.name }}-{{ item.revision }} lxc.arch = amd64 +{% if item.extra is defined %} -{{ lxc_extra }} +{{ item.extra }} +{% endif %} diff --git a/site.yml b/site.yml index fc0dd1e..06b288a 100644 --- a/site.yml +++ b/site.yml @@ -7,7 +7,11 @@ - name: install python3 raw: test -e /usr/bin/python3 || (apt-get update && apt-get install -y python3) || (xbps-install -S && xbps-install python) -- hosts: fet +- hosts: fet_hosts + roles: + - common + +- hosts: fet_containers roles: - common