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

36 lines
1.4 KiB
YAML

---
# Not using the hostname module on purpose, because at this point Python has
# not yet been install on the container.
#
- 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"
- name: "Set container hostname"
delegate_to: "{{ hostvars[inventory_hostname].lxd_host }}"
shell: >-
lxc exec {{ inventory_hostname }}
hostnamectl set-hostname {{ hostvars[inventory_hostname].hostname | quote}}
when: hostvars[inventory_hostname].distribution_codename != "trusty"
tags: [ hostname ]
- name: "Set container hostname (Ubuntu 14.04)"
delegate_to: "{{ hostvars[inventory_hostname].lxd_host }}"
shell: >-
lxc exec {{ inventory_hostname }} -- bash -c
"echo {{ hostvars[inventory_hostname].hostname | quote}} > /etc/hostname"
when: hostvars[inventory_hostname].distribution_codename == "trusty"
tags: [ hostname ]
- name: "Activate container hostname (Ubuntu 14.04)"
delegate_to: "{{ hostvars[inventory_hostname].lxd_host }}"
shell: >-
lxc exec {{ inventory_hostname }}
hostname {{ hostvars[inventory_hostname].hostname | quote}}
when: hostvars[inventory_hostname].distribution_codename == "trusty"
tags: [ hostname ]