Browse Source

Auto-updating guest VM DNS config via bind-mount.

services
Slash 9 years ago
parent
commit
ddf6e6ff04
3 changed files with 10 additions and 1 deletions
  1. +6
    -0
      roles/lxc_guest/tasks/main.yaml
  2. +3
    -1
      roles/lxc_guest/templates/config.j2
  3. +1
    -0
      roles/lxc_guest/templates/resolv.conf.j2

+ 6
- 0
roles/lxc_guest/tasks/main.yaml View File

@ -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 }}"


+ 3
- 1
roles/lxc_guest/templates/config.j2 View File

@ -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 %}

+ 1
- 0
roles/lxc_guest/templates/resolv.conf.j2 View File

@ -0,0 +1 @@
nameserver {{ hostvars[ext_gateway]['ansible_host'] }}

Loading…
Cancel
Save