diff --git a/playbooks/roles/bifrost-ironic-install/tasks/bootstrap.yml b/playbooks/roles/bifrost-ironic-install/tasks/bootstrap.yml index 02f903c3f..d9f714273 100644 --- a/playbooks/roles/bifrost-ironic-install/tasks/bootstrap.yml +++ b/playbooks/roles/bifrost-ironic-install/tasks/bootstrap.yml @@ -232,6 +232,51 @@ group: "root" mode: 0755 when: inventory_dhcp | bool == true +- name: "Retrieve interface IP informations" + set_fact: + itf_infos: "{{ hostvars[inventory_hostname]['ansible_' + ans_network_interface]['ipv4'] }}" + dhcp_netaddr: "{{ dhcp_pool_start }}/{{ dhcp_static_mask }}" + when: include_dhcp_server | bool == true +- name: "Compute interface and DHCP network informations" + set_fact: + itf_netaddr1: "{{ itf_infos['address'] }}/{{ itf_infos['netmask'] }}" + itf_netaddr2: "{{ itf_infos['network'] }}/{{ itf_infos['netmask'] }}" + itf_broadcast: "{{ itf_infos['broadcast'] }}/{{ itf_infos['netmask'] }}" + dhcp_netaddr: "{{ dhcp_netaddr | ipaddr('network') }}/{{ dhcp_static_mask }}" + when: include_dhcp_server | bool == true +- name: "Validate interface network addresses" + fail: msg="Interface {{ ans_network_interface }} network incoherence {{ itf_netaddr1 | ipaddr('network') }}/{{ itf_netaddr1 | ipaddr('prefix') }} vs {{ itf_netaddr2 }}/{{ itf_netaddr2 | ipaddr('prefix') }}" + when: + - include_dhcp_server | bool == true + - itf_netaddr1 | ipaddr('network') != itf_netaddr2 | ipaddr('network') +- name: "Validate interface broadcast addresses" + fail: msg="Interface {{ ans_network_interface }} broadcast incoherence {{ itf_netaddr1 | ipaddr('broadcast') }}/{{ itf_netaddr1 | ipaddr('prefix') }} vs {{ itf_broadcast | ipaddr('broadcast') }}/{{ itf_broadcast | ipaddr('prefix') }}" + when: + - include_dhcp_server | bool == true + - itf_netaddr1 | ipaddr('broadcast') != itf_broadcast | ipaddr('broadcast') +- name: "Validate DHCP and interface addresses" + debug: msg="Interface {{ ans_network_interface }} and DHCP networks are incoherent {{ itf_netaddr2 | ipaddr('network') }}/{{ itf_netaddr2 | ipaddr('prefix') }} {{ dhcp_netaddr | ipaddr('network') }}/{{ dhcp_netaddr | ipaddr('prefix') }} overriding DHCP with interface settings" + when: + - include_dhcp_server | bool == true + - itf_netaddr2 | ipaddr('network') != dhcp_netaddr | ipaddr('network') +- name: "Computing new DHCP informations" + set_fact: + dhcp_start_ip: "{{ dhcp_pool_start.split('.')[-1] }}" + dhcp_end_ip: "{{ dhcp_pool_end.split('.')[-1] }}" + dhcp_netaddr: "{{ itf_netaddr1 | ipaddr('network') }}" + when: + - include_dhcp_server | bool == true + - itf_netaddr2 | ipaddr('network') != dhcp_netaddr | ipaddr('network') +# Note(olivierbourdon38): we could do much more complex network +# computation to derive exact (or way closer to exact) range for +# the new network depending on netmasks and indexes. +- name: "Computing new DHCP range" + set_fact: + dhcp_pool_start: "{{ '.'.join(dhcp_netaddr.split('.')[0:-1]) }}.{{ dhcp_start_ip }}" + dhcp_pool_end: "{{ '.'.join(dhcp_netaddr.split('.')[0:-1]) }}.{{ dhcp_end_ip }}" + when: + - include_dhcp_server | bool == true + - itf_netaddr2 | ipaddr('network') != dhcp_netaddr | ipaddr('network') - name: "Deploy dnsmasq configuration file" template: src=dnsmasq.conf.j2 dest=/etc/dnsmasq.conf when: include_dhcp_server | bool == true