sidn-lxd-ansible-demo/roles/lxd_container/tasks/bootstrap.yml

92 lines
3.3 KiB
YAML

---
- include: bootstrap-ubuntu14.04.yml
when: >
inventory_hostname not in lxd_status and
vars.distribution_codename == 'trusty'
- include: bootstrap-other.yml
when: >
inventory_hostname not in lxd_status and
vars.distribution_codename != 'trusty'
- name: "Set interface MAC addresses"
delegate_to: "{{ hostvars[inventory_hostname].lxd_host }}"
shell: >-
lxc config set
{{ hostvars[inventory_hostname].lxd_host | quote }}:{{ inventory_hostname | quote }}
volatile.{{ item.interface | quote }}.hwaddr {{ item.mac_address | quote}}
with_items: "{{ hostvars[inventory_hostname].network.values() | list }}"
when: '"mac_address" in item'
- name: "Set LXD configuration parameters"
delegate_to: "{{ hostvars[inventory_hostname].lxd_host }}"
shell: >-
lxc config set
{{ hostvars[inventory_hostname].lxd_host | quote }}:{{ inventory_hostname | quote }}
{{ item.name | quote }} {{ item.value | quote }}
with_items:
- name: boot.autostart
value: 1
- name: boot.autostart.delay
value: 1
- name: boot.autostart.priority
value: "{{ hostvars[inventory_hostname].lxd_boot_priority | default(0) }}"
- name: "Make NFS client work in the container"
delegate_to: "{{ hostvars[inventory_hostname].lxd_host }}"
shell: >-
lxc config set
{{ hostvars[inventory_hostname].lxd_host | quote }}:{{ inventory_hostname | quote }}
{{ item.name | quote }} {{ item.value | quote }}
with_items:
- name: "raw.apparmor"
value: "mount fstype=nfs,"
- name: "security.privileged"
value: "true"
when: '"nfs_mount" in hostvars[inventory_hostname]'
- include: hostname.yml
- name: "Stop created LXD container"
delegate_to: "{{ hostvars[inventory_hostname].lxd_host }}"
lxd_container:
name: "{{ inventory_hostname }}"
state: stopped
when: inventory_hostname not in lxd_status
- name: "Start created LXD container"
delegate_to: "{{ hostvars[inventory_hostname].lxd_host }}"
lxd_container:
name: "{{ inventory_hostname }}"
state: started
wait_for_ipv4_addresses: True
when: inventory_hostname not in lxd_status
- name: "Update packages on created LXD container"
delegate_to: "{{ hostvars[inventory_hostname].lxd_host }}"
shell: lxc exec {{ inventory_hostname }} -- apt-get update
when: inventory_hostname not in lxd_status
- name: "Upgrade packages on created LXD container"
delegate_to: "{{ hostvars[inventory_hostname].lxd_host }}"
shell: lxc exec {{ inventory_hostname }} -- apt-get upgrade -y
when: inventory_hostname not in lxd_status
- name: "Autoremove packages on created LXD container"
delegate_to: "{{ hostvars[inventory_hostname].lxd_host }}"
shell: lxc exec {{ inventory_hostname }} -- apt-get autoremove -y
when: inventory_hostname not in lxd_status
- name: "Autoclean packages on created LXD container"
delegate_to: "{{ hostvars[inventory_hostname].lxd_host }}"
shell: lxc exec {{ inventory_hostname }} -- apt-get autoclean -y
when: inventory_hostname not in lxd_status
- name: "Disable hostname management from cloud-init"
delegate_to: "{{ hostvars[inventory_hostname].lxd_host }}"
shell: >-
lxc exec {{ inventory_hostname }} --
sed -i -e 's/^\\s*preserve_hostname\\s*:.*/preserve_hostname: true/' /etc/cloud/cloud.cfg
tags: [ hostname ]
when: hostvars[inventory_hostname].distribution_codename != "trusty"