forked from evolix/ansible-roles
23a486dc9a
Right now lxc containers are in the Etc/UTC timezone, this commit change it so that they are in the same timezone as the host by copying /etc/timezone and /etc/localtime (without dereferencing it) inside of the container. It might not be able to survive an update of the tzdata package however. (Debian shouldn't change manual configuration upon update but they chose to anyways so bear with it).
76 lines
2.2 KiB
YAML
76 lines
2.2 KiB
YAML
---
|
|
- name: "Check if container {{ name }} exists"
|
|
command: "lxc-ls {{ name }}"
|
|
changed_when: false
|
|
check_mode: no
|
|
register: container_exists
|
|
|
|
- name: "Create container {{ name }}"
|
|
lxc_container:
|
|
name: "{{ name }}"
|
|
container_log: true
|
|
template: debian
|
|
state: stopped
|
|
template_options: "--arch amd64 --release {{ release }}"
|
|
when: container_exists.stdout_lines == []
|
|
|
|
- name: "Disable network configuration inside container {{ name }}"
|
|
replace:
|
|
name: "/var/lib/lxc/{{ name }}/rootfs/etc/default/networking"
|
|
regexp: "^#CONFIGURE_INTERFACES=yes"
|
|
replace: CONFIGURE_INTERFACES=no
|
|
when: lxc_network_type == "none"
|
|
|
|
- name: "Disable interface shut down on halt inside container {{ name }} (Jessie container)"
|
|
lineinfile:
|
|
name: "/var/lib/lxc/{{ name }}/rootfs/etc/default/halt"
|
|
line: "NETDOWN=no"
|
|
when: lxc_network_type == "none" and release == "jessie"
|
|
|
|
- name: "Make the container {{ name }} poweroff on SIGPWR sent by lxc-stop (Jessie container)"
|
|
file:
|
|
src: /lib/systemd/system/poweroff.target
|
|
dest: "/var/lib/lxc/{{ name }}/rootfs/etc/systemd/system/sigpwr.target"
|
|
state: link
|
|
when: release == 'jessie'
|
|
|
|
- name: "Configure the DNS resolvers in the container {{ name }}"
|
|
copy:
|
|
remote_src: yes
|
|
src: /etc/resolv.conf
|
|
dest: "/var/lib/lxc/{{ name }}/rootfs/etc/"
|
|
|
|
- name: "Add hostname in /etc/hosts for container {{ name }}"
|
|
lineinfile:
|
|
name: "/var/lib/lxc/{{ name }}/rootfs/etc/hosts"
|
|
line: "127.0.0.1 {{ name }}"
|
|
|
|
- name: "Fix permission on /dev for container {{ name }}"
|
|
lineinfile:
|
|
name: "/var/lib/lxc/{{ name }}/rootfs/etc/rc.local"
|
|
line: "chmod 755 /dev"
|
|
insertbefore: "^exit 0$"
|
|
when: release == 'jessie'
|
|
|
|
- name: "Force container {{ name }} to be in the correct timezone [1/2]"
|
|
copy:
|
|
src: "/etc/timezone"
|
|
dest: "/var/lib/lxc/{{ name }}/rootfs/etc/timezone"
|
|
force: yes
|
|
owner: root
|
|
group: root
|
|
|
|
- name: "Force container {{ name }} to be in the correct timezone [2/2]"
|
|
copy:
|
|
src: "/etc/localtime"
|
|
dest: "/var/lib/lxc/{{ name }}/rootfs/etc/localtime"
|
|
force: yes
|
|
local_follow: no
|
|
owner: root
|
|
group: root
|
|
|
|
- name: "Ensure that {{ name }} container is running"
|
|
lxc_container:
|
|
name: "{{ name }}"
|
|
state: started
|