--- # Copyright Red Hat, Inc. # All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. - name: Converge hosts: all vars: cifmw_dnsmasq_enable_dns: true cifmw_dnsmasq_interfaces: - mol-test-1 - mol-test-2 cifmw_dnsmasq_listen_addresses: - "192.168.253.9" - "192.168.254.9" cifmw_dnsmasq_raw_config: |- dhcp-authoritative log-dhcp roles: - role: "dnsmasq" tasks: - name: Create network vars: cifmw_dnsmasq_network_name: starwars cifmw_dnsmasq_network_state: present cifmw_dnsmasq_network_definition: ranges: - label: ian start_v4: 192.168.254.10 start_v6: "2345:0425:2CA1::0567:5673:23b5" domain: "starwars.lan" options: - "3,192.168.254.1" - "option6:dns-server,[2345:0425:2CA1::0567:5673:0001]" ansible.builtin.include_role: name: dnsmasq tasks_from: manage_network.yml - name: Create second network vars: cifmw_dnsmasq_network_name: startrek cifmw_dnsmasq_network_state: present cifmw_dnsmasq_listen_addresses: - "192.168.253.1" - "2345:0426:2CA1::0567:5673:23b0" cifmw_dnsmasq_network_definition: ranges: - label: ian domain: "startrek.lan" start_v4: 192.168.253.10 prefix_length_v4: 26 start_v6: "2345:0426:2CA1::0567:5673:23b5" prefix_length_v6: 120 ansible.builtin.include_role: name: dnsmasq tasks_from: manage_network.yml - name: Check for enable-ra line in startrek block: - name: Inject enable-ra in startrek become: true register: _enable_ra ansible.builtin.lineinfile: line: "enable-ra" path: "/etc/cifmw-dnsmasq.d/startrek.conf" - name: Assert no change was done in startrek ansible.builtin.assert: that: - _enable_ra is not changed msg: >- ipv6 not properly detected. - name: Create IPv4-only network vars: cifmw_dnsmasq_network_name: oldies cifmw_dnsmasq_network_state: present cifmw_dnsmasq_listen_addresses: - "192.168.252.1" cifmw_dnsmasq_network_definition: ranges: - label: goodies domain: "goodies.lan" start_v4: 192.168.252.10 start_v6: '' prefix_length_v4: 26 ansible.builtin.include_role: name: dnsmasq tasks_from: manage_network.yml - name: Check for enable-ra line in oldies block: - name: Inject enable-ra in oldies become: true register: _set_ra ansible.builtin.lineinfile: line: "enable-ra" path: "/etc/cifmw-dnsmasq.d/oldies.conf" - name: Debug ansible.builtin.debug: var: _set_ra - name: Assert oldies was changed ansible.builtin.assert: that: - _set_ra is changed - name: Inject some node in starwars network vars: cifmw_dnsmasq_dhcp_entries: - network: starwars state: present mac: "0a:19:02:f8:4c:a7" ips: - "2345:0425:2CA1::0567:5673:cafe" - "192.168.254.11" - network: starwars state: present mac: "0a:19:02:f8:4c:a8" ips: - "2345:0425:2CA1::0567:5673:babe" - "192.168.254.12" name: "solo" - network: startrek state: present mac: "0a:19:02:f8:4c:a8" ips: - "2345:0426:2CA1::0567:5673:babe" - "192.168.253.12" name: "spock" ansible.builtin.include_role: name: dnsmasq tasks_from: manage_host.yml - name: Inject nodes with tags for DHCP options vars: cifmw_dnsmasq_dhcp_entries: - network: starwars state: present mac: "0a:19:02:f8:4c:b1" ips: - "192.168.254.21" - "2345:0425:2CA1::0567:5673:0021" name: "r2d2" tag: "droid" - network: starwars state: present mac: "0a:19:02:f8:4c:b2" ips: - "192.168.254.22" name: "c3po" tag: "droid" - network: startrek state: present mac: "0a:19:02:f8:4c:b3" ips: - "192.168.253.31" name: "data" tag: "android" ansible.builtin.include_role: name: dnsmasq tasks_from: manage_host.yml - name: Verify DHCP host entries with tags block: - name: Read r2d2 DHCP host entry become: true ansible.builtin.slurp: path: "/etc/cifmw-dnsmasq.d/dhcp-hosts.d/starwars_r2d2_0a:19:02:f8:4c:b1" register: _r2d2_entry - name: Read c3po DHCP host entry become: true ansible.builtin.slurp: path: "/etc/cifmw-dnsmasq.d/dhcp-hosts.d/starwars_c3po_0a:19:02:f8:4c:b2" register: _c3po_entry - name: Read data DHCP host entry become: true ansible.builtin.slurp: path: "/etc/cifmw-dnsmasq.d/dhcp-hosts.d/startrek_data_0a:19:02:f8:4c:b3" register: _data_entry - name: Decode entries ansible.builtin.set_fact: _r2d2_content: "{{ _r2d2_entry.content | b64decode | trim }}" _c3po_content: "{{ _c3po_entry.content | b64decode | trim }}" _data_content: "{{ _data_entry.content | b64decode | trim }}" - name: Assert r2d2 entry has droid tag ansible.builtin.assert: that: - "'set:droid' in _r2d2_content" - "'0a:19:02:f8:4c:b1' in _r2d2_content" - "'192.168.254.21' in _r2d2_content" - "'r2d2' in _r2d2_content" msg: "r2d2 DHCP entry should contain tag 'droid': {{ _r2d2_content }}" - name: Assert c3po entry has droid tag ansible.builtin.assert: that: - "'set:droid' in _c3po_content" - "'0a:19:02:f8:4c:b2' in _c3po_content" - "'192.168.254.22' in _c3po_content" - "'c3po' in _c3po_content" msg: "c3po DHCP entry should contain tag 'droid': {{ _c3po_content }}" - name: Assert data entry has android tag ansible.builtin.assert: that: - "'set:android' in _data_content" - "'0a:19:02:f8:4c:b3' in _data_content" - "'192.168.253.31' in _data_content" - "'data' in _data_content" msg: "data DHCP entry should contain tag 'android': {{ _data_content }}" - name: "Verify entry without tag has no set: prefix" become: true ansible.builtin.slurp: path: "/etc/cifmw-dnsmasq.d/dhcp-hosts.d/starwars_solo_0a:19:02:f8:4c:a8" register: _solo_entry - name: "Assert solo entry does not have a tag" vars: _solo_content: "{{ _solo_entry.content | b64decode | trim }}" ansible.builtin.assert: that: - "'set:' not in _solo_content" - "'0a:19:02:f8:4c:a8' in _solo_content" - "'solo' in _solo_content" msg: "solo DHCP entry should not contain any tag: {{ _solo_content }}" - name: "Create DHCP options configuration for tagged hosts" become: true ansible.builtin.copy: dest: "/etc/cifmw-dnsmasq.d/test-dhcp-options.conf" content: | # Test DHCP options for droids dhcp-option=tag:droid,60,HTTPClient dhcp-option=tag:droid,67,http://192.168.254.1/droid-boot.ipxe # Test DHCP options for androids dhcp-option=tag:android,60,HTTPClient dhcp-option=tag:android,67,http://192.168.253.1/android-boot.ipxe mode: '0644' validate: "/usr/sbin/dnsmasq -C %s --test" notify: Restart dnsmasq - name: Verify dnsmasq configuration is valid become: true ansible.builtin.command: cmd: /usr/sbin/dnsmasq -C /etc/cifmw-dnsmasq.conf --test changed_when: false - name: Add a domain specific forwarder vars: cifmw_dnsmasq_forwarder: - state: present server: 192.168.254.100 domains: - battlestar.galactica.lan ansible.builtin.include_role: name: dnsmasq tasks_from: manage_forwarder.yml - name: Add some host records vars: cifmw_dnsmasq_host_record: - state: present ips: - "192.168.253.50" - "2345:0425:2CA1::dead" names: - dead.battlestar.galactica.lan - state: present ips: - "192.168.253.51" - "2345:0425:2CA1::beef" names: - beef.battlestar.galactica.lan ansible.builtin.include_role: name: dnsmasq tasks_from: manage_host_record.yml - name: Add some wildcard addresses vars: cifmw_dnsmasq_address: - state: present ipaddr: "1.2.3.4" domains: - apps.ocp.starwars.lan - state: present ipaddr: "4.3.2.1" domains: - apps.ocp.startrek.lan ansible.builtin.include_role: name: dnsmasq tasks_from: manage_address.yml - name: Force reload dnsmasq ansible.builtin.meta: flush_handlers