From 9bd2c8c17a22c84da9a6ba6407c5b928d77fb469 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romain=20Gon=C3=A7alves?= Date: Tue, 7 Dec 2021 15:41:02 +0000 Subject: roles/vmm: Serve autoinstall configurations via httpd --- roles/vmm/tasks/autoinstall-configuration.yml | 27 +++++++++++++++++++++ roles/vmm/tasks/disk.yml | 2 +- roles/vmm/tasks/facts.yml | 8 +++---- roles/vmm/tasks/main.yml | 34 ++++++--------------------- roles/vmm/tasks/network.yml | 27 +++++++++++++++++++++ 5 files changed, 66 insertions(+), 32 deletions(-) create mode 100644 roles/vmm/tasks/autoinstall-configuration.yml create mode 100644 roles/vmm/tasks/network.yml (limited to 'roles/vmm/tasks') diff --git a/roles/vmm/tasks/autoinstall-configuration.yml b/roles/vmm/tasks/autoinstall-configuration.yml new file mode 100644 index 0000000..e05b11c --- /dev/null +++ b/roles/vmm/tasks/autoinstall-configuration.yml @@ -0,0 +1,27 @@ +- name: include httpd role variables + include_vars: "{{ inventory_dir }}/roles/httpd/defaults/main.yml" + +- name: create autoinstall directory + file: + path: /var/www/htdocs/autoinstall + owner: www + group: www + mode: 0700 + state: directory + +- name: generate autoinstall files + template: + src: autoinstall.conf.j2 + dest: "/var/www/htdocs/autoinstall/{{ item.lladdr }}-install.conf" + owner: www + group: www + mode: 0640 + loop: "{{ vmm_vms }}" + +- name: generate httpd configuration + template: + src: httpd.conf.j2 + dest: "{{ httpd_configuration_dir }}/autoinstall.conf" + owner: 0 + group: 0 + mode: 0640 diff --git a/roles/vmm/tasks/disk.yml b/roles/vmm/tasks/disk.yml index 24dd491..423d855 100644 --- a/roles/vmm/tasks/disk.yml +++ b/roles/vmm/tasks/disk.yml @@ -2,7 +2,7 @@ command: cmd: vmctl create -s "{{ item.size }}" "{{ item.name }}.{{ vmm_disk_format }}" chdir: "{{ vmm_disk_dir }}" - loop: "{{ __vms }}" + loop: "{{ vmm_vms }}" register: result changed_when: result.rc == 0 failed_when: diff --git a/roles/vmm/tasks/facts.yml b/roles/vmm/tasks/facts.yml index 7cf4f0c..c7b453b 100644 --- a/roles/vmm/tasks/facts.yml +++ b/roles/vmm/tasks/facts.yml @@ -1,14 +1,14 @@ - name: generate lladdr variable for virtual machines set_fact: - tmp_vms: > - {{ tmp_vms | default([]) + [ item | combine({ + vmm_vms_tmp: > + {{ vmm_vms_tmp | default([]) + [ item | combine({ 'lladdr': item.name | hash('sha1') | truncate(12, True, '') | ansible.netcommon.hwaddr('unix') }) ] }} - loop: "{{ __vms }}" + loop: "{{ vmm_vms }}" - name: save variables set_fact: - __vms: "{{ tmp_vms }}" + vmm_vms: "{{ vmm_vms_tmp }}" diff --git a/roles/vmm/tasks/main.yml b/roles/vmm/tasks/main.yml index 3c5a462..c596664 100644 --- a/roles/vmm/tasks/main.yml +++ b/roles/vmm/tasks/main.yml @@ -13,6 +13,10 @@ - name: include facts generation include_tasks: facts.yml +- name: include autoinstall generation + include_tasks: autoinstall-configuration.yml + tags: task_autoinstall_configuration + - name: include iso management include_tasks: iso.yml tags: task_iso @@ -21,33 +25,9 @@ include_tasks: disk.yml tags: task_disk -- name: start ip forwarding - command: sysctl net.inet.ip{{ item }}.forwarding=1 - loop: "{{ vmm_network_forwarded_ips }}" - -- name: enable ip forwarding - lineinfile: - path: /etc/sysctl.conf - regexp: "^net.inet.ip{{ item }}.forwarding=" - line: "net.inet.ip{{ item }}.forwarding=1" - owner: 0 - group: 0 - mode: 0640 - create: true - loop: "{{ vmm_network_forwarded_ips }}" - -- name: create network switch - lineinfile: - path: "/etc/hostname.{{ vmm_network_switch.interface }}" - regexp: &network_line "add {{ ansible_default_ipv4.interface }}" - line: *network_line - owner: 0 - group: 0 - mode: 0640 - create: true - -- name: start network switch - command: "sh /etc/netstart {{ vmm_network_switch.interface }}" +- name: include network management + include_tasks: network.yml + tags: task_network - name: generate vmm configuration template: diff --git a/roles/vmm/tasks/network.yml b/roles/vmm/tasks/network.yml new file mode 100644 index 0000000..b8fc7e1 --- /dev/null +++ b/roles/vmm/tasks/network.yml @@ -0,0 +1,27 @@ +- name: start ip forwarding + command: sysctl net.inet.ip{{ item }}.forwarding=1 + loop: "{{ vmm_network_forwarded_ips }}" + +- name: enable ip forwarding + lineinfile: + path: /etc/sysctl.conf + regexp: "^net.inet.ip{{ item }}.forwarding=" + line: "net.inet.ip{{ item }}.forwarding=1" + owner: 0 + group: 0 + mode: 0640 + create: true + loop: "{{ vmm_network_forwarded_ips }}" + +- name: create network switch + lineinfile: + path: "/etc/hostname.{{ vmm_network_switch.interface }}" + regexp: &network_line "add {{ ansible_default_ipv4.interface }}" + line: *network_line + owner: 0 + group: 0 + mode: 0640 + create: true + +- name: start network switch + command: "sh /etc/netstart {{ vmm_network_switch.interface }}" -- cgit v1.2.3