From ddf6e6ff041cb553a7d51737c082ce242ba6bd71 Mon Sep 17 00:00:00 2001 From: Slash Date: Sun, 29 May 2016 12:18:09 +0200 Subject: [PATCH] Auto-updating guest VM DNS config via bind-mount. --- roles/lxc_guest/tasks/main.yaml | 6 ++++++ roles/lxc_guest/templates/config.j2 | 4 +++- roles/lxc_guest/templates/resolv.conf.j2 | 1 + 3 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 roles/lxc_guest/templates/resolv.conf.j2 diff --git a/roles/lxc_guest/tasks/main.yaml b/roles/lxc_guest/tasks/main.yaml index ae2753d..8d25193 100644 --- a/roles/lxc_guest/tasks/main.yaml +++ b/roles/lxc_guest/tasks/main.yaml @@ -21,6 +21,9 @@ state: stopped - name: deploy container config template: src=config.j2 dest="/var/lib/lxc/{{ vm_name }}/config" + - name: update container DNS configuration + template: src=resolv.conf.j2 dest="/var/lib/lxc/{{ vm_name }}/resolv.conf" + register: container_config_update - name: start container lxc_container: name: "{{ vm_name }}" @@ -31,6 +34,9 @@ - name: update container config template: src=config.j2 dest="/var/lib/lxc/{{ vm_name }}/config" register: container_config_update + - name: update container DNS configuration + template: src=resolv.conf.j2 dest="/var/lib/lxc/{{ vm_name }}/resolv.conf" + register: container_config_update - name: restart container lxc_container: name: "{{ vm_name }}" diff --git a/roles/lxc_guest/templates/config.j2 b/roles/lxc_guest/templates/config.j2 index 6b2fc20..e051aab 100644 --- a/roles/lxc_guest/templates/config.j2 +++ b/roles/lxc_guest/templates/config.j2 @@ -6,10 +6,12 @@ lxc.rootfs = /dev/{{ inventory_hostname }}vg/vm_{{ vm_name }} lxc.tty = 4 lxc.arch = amd64 +lxc.mount.entry = /var/lib/lxc/{{ vm_name }}/resolv.conf etc/resolv.conf none ro,bind,create=file + lxc.network.type = veth lxc.network.flags = up lxc.network.link = br0 lxc.network.name = eth0 -lxc.network.ipv4 = {{ hostvars[vm_name]['ansible_host'] }}/24 +lxc.network.ipv4 = {{ hostvars[vm_name]['ansible_host'] }}/16 lxc.network.ipv4.gateway = {{ hostvars[ext_gateway]['ansible_host'] }} lxc.start.auto = {% if auto_start %}1{% else %}0{% endif %} diff --git a/roles/lxc_guest/templates/resolv.conf.j2 b/roles/lxc_guest/templates/resolv.conf.j2 new file mode 100644 index 0000000..32b139c --- /dev/null +++ b/roles/lxc_guest/templates/resolv.conf.j2 @@ -0,0 +1 @@ +nameserver {{ hostvars[ext_gateway]['ansible_host'] }}