commit bd5282ad87427606f0f3bc61e6748bd0e7309963 Author: nd Date: Wed Nov 15 00:24:29 2017 +0100 Initial commit diff --git a/defaults/main.yml b/defaults/main.yml new file mode 100644 index 0000000..338f303 --- /dev/null +++ b/defaults/main.yml @@ -0,0 +1 @@ +rootpath: '' diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100644 index 0000000..31c06c7 --- /dev/null +++ b/tasks/main.yml @@ -0,0 +1,20 @@ +- name: install dbus (needed to set the hostname with systemd) + apt: + pkg: dbus + when: rootpath == "" + +- name: set hostname with systemd + hostname: + name: "{{ inventory_hostname }}" + when: rootpath == "" + +- name: customize vm image hostname + copy: + dest: "{{ rootpath }}/etc/hostname" + content: '{{ inventory_hostname_short }}' + +- name: customize vm image hosts file + template: + src: hosts.j2 + dest: "{{ rootpath }}/etc/hosts" + diff --git a/templates/hosts.j2 b/templates/hosts.j2 new file mode 100644 index 0000000..3d782c6 --- /dev/null +++ b/templates/hosts.j2 @@ -0,0 +1,10 @@ +127.0.0.1 localhost +::1 localhost ip6-localhost ip6-loopback +ff02::1 ip6-allnodes +ff02::2 ip6-allrouters + +{% for n in vm['nics']|default([]) %} +{% for i in vm['nics'][n].protocol if vm['nics'][n].protocol[i].type == "static" %} +{{vm['nics'][n].protocol[i].options['address']}} {{ inventory_hostname }} {{ inventory_hostname_short }} +{% endfor %} +{% endfor %}