From 6e4edfb5a80d5ba3e3b52149f3e504791dfa7d50 Mon Sep 17 00:00:00 2001 From: "Daniel A. Maierhofer" Date: Sat, 17 Mar 2018 16:25:24 +0100 Subject: [PATCH] Add LXC initial SSH setup --- group_vars/fet_containers | 2 ++ hosts/production | 5 ++--- roles/ariane/handlers/main.yml | 5 +++++ roles/ariane/tasks/lxc.yml | 16 +++++++++++++++- 4 files changed, 24 insertions(+), 4 deletions(-) create mode 100644 group_vars/fet_containers diff --git a/group_vars/fet_containers b/group_vars/fet_containers new file mode 100644 index 0000000..3f9a804 --- /dev/null +++ b/group_vars/fet_containers @@ -0,0 +1,2 @@ +--- +common_apt: False diff --git a/hosts/production b/hosts/production index 2405809..537dc55 100644 --- a/hosts/production +++ b/hosts/production @@ -3,11 +3,10 @@ all: fet_hosts: hosts: ariane: - lxc-pet-01: - betam: - fet_container: + fet_containers: hosts: lxc-pet-01: betam: + zyklon: vars: ansible_python_interpreter=/usr/bin/python3 diff --git a/roles/ariane/handlers/main.yml b/roles/ariane/handlers/main.yml index 966282b..47beca3 100644 --- a/roles/ariane/handlers/main.yml +++ b/roles/ariane/handlers/main.yml @@ -16,3 +16,8 @@ - name: restart smartd service: name=smartd state=restarted + +- name: lxc - create authorized_keys file in VM for root + listen: lxc - inital ssh authorized_keys + copy: remote_src=yes src=/root/.ssh/authorized_keys dest="/var/lib/lxc/lxc-{{ item.name }}-{{ item.revision }}/rootfs/root/.ssh/authorized_keys" owner=root group=root mode=0600 + with_items: "{{ lxc.containers }}" diff --git a/roles/ariane/tasks/lxc.yml b/roles/ariane/tasks/lxc.yml index 59c3325..831b669 100644 --- a/roles/ariane/tasks/lxc.yml +++ b/roles/ariane/tasks/lxc.yml @@ -33,5 +33,19 @@ lxc_container: name: "lxc-{{ item.name }}-{{ item.revision }}" template: "{{ item.template }}" - container_config: "{{ item.config}}" + container_config: "{{ item.config }}" with_items: "{{ lxc.containers }}" + notify: lxc - inital ssh setup + +- name : lxc - enable ssh on voidlinux + lxc_container: + name: "lxc-{{ item.name }}-{{ item.revision }}" + container_command: "ln -s /etc/sv/{sshd,dhcpcd-eth0} /var/service/" + when: item.template == "voidlinux" + changed_when: False + with_items: "{{ lxc.containers }}" + +- name: lxc - create .ssh directory for root in VM + file: path="/var/lib/lxc/lxc-{{ item.name }}-{{ item.revision }}/rootfs/root/.ssh" state=directory owner=root group=root mode=0700 + with_items: "{{ lxc.containers }}" + notify: lxc - inital ssh authorized_keys