Skip to content

Commit

Permalink
[dnsmasq] moved domain logic into networking definition
Browse files Browse the repository at this point in the history
Signed-off-by: Roberto Alfieri <ralfieri@redhat.com>
  • Loading branch information
rebtoor committed May 23, 2024
1 parent dc26d57 commit e2750f9
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 19 deletions.
1 change: 1 addition & 0 deletions docs/dictionary/en-custom.txt
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ modprobe
mountpoints
mtcylje
mtu
multiline
multinode
multipath
multus
Expand Down
2 changes: 1 addition & 1 deletion roles/dnsmasq/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ supported in libvirt).
* `cifmw_dnsmasq_listen_addresses`: (List) List of IP addresses on which dnsmasq should be enabled. Defaults to `[]`.
* `cifmw_dnsmasq_enable_dns`: (Bool) Toggle to enable DNS features of dnsmasq. Defaults to `false`.
* `cifmw_dnsmasq_addresses`: (List) Specify a list of IP addresses to return for any host in the given domains. Defaults to `[]`.
* `cifmw_dnsmasq_domain_name`: (String) DNS domain name used for the DHCP server. Defaults to `''`.

#### Ranges mapping

* `label`: (String) Network label ("tag" in dnsmasq manual).
* `domain`: (String) domain name associated to the dhcp range.
* `start_v4`: (String) IPv4 starting IP.
* `start_v6`: (String) IPv6 starting IP.
* `prefix_length_v4`: (Int) IPv4 prefix length. Defaults to `24`.
Expand Down
1 change: 0 additions & 1 deletion roles/dnsmasq/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,3 @@ cifmw_dnsmasq_interfaces: []
cifmw_dnsmasq_listen_addresses: []
cifmw_dnsmasq_enable_dns: false
cifmw_dnsmasq_addresses: []
cifmw_dnsmasq_domain_name: ''
10 changes: 4 additions & 6 deletions roles/dnsmasq/molecule/default/converge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,10 @@
cifmw_dnsmasq_enable_dns: true
cifmw_dnsmasq_interfaces:
- mol-test-1
cifmw_dnsmasq_addresses:
- fqdn: "api.ocp.openstack.lab"
address: "192.168.122.2"
- fqdn: ".apps.ocp.openstack.lab"
address: "192.168.122.3"
- mol-test-2
cifmw_dnsmasq_listen_addresses:
- "192.168.253.9"
- "192.168.254.9"
cifmw_dnsmasq_domain_name: "ocp.openstack.lab"
cifmw_dnsmasq_raw_config: |-
dhcp-authoritative
log-dhcp
Expand All @@ -44,6 +40,7 @@
- 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]"
Expand All @@ -61,6 +58,7 @@
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"
Expand Down
5 changes: 0 additions & 5 deletions roles/dnsmasq/templates/dns.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@
server={{ forwarder }}
{% endfor %}

{% if cifmw_dnsmasq_domain_name != '' -%}
domain={{ cifmw_dnsmasq_domain_name }}
local=/{{ cifmw_dnsmasq_domain_name }}/
{% endif %}

{% for entry in cifmw_dnsmasq_addresses -%}
address=/{{ entry.fqdn }}/{{ entry.address }}
{% endfor %}
18 changes: 12 additions & 6 deletions roles/dnsmasq/templates/network.conf.j2
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
# Managed by ci-framework/dnsmasq

{% for range in cifmw_dnsmasq_network_definition['ranges'] %}
{% if range.start_v4 is defined and range.start_v4 | length > 0 %}
dhcp-range=set:{{ range.label }},{{ range.start_v4 }},static,{{ (range.start_v4 + "/" + range.prefix_length_v4 | default(24) | string) | ansible.utils.ipaddr('netmask') }},{{ range.ttl | default('1h') }}
{% for range in cifmw_dnsmasq_network_definition['ranges'] -%}
{% if range.start_v4 is defined and range.start_v4 | length > 0 -%}
dhcp-range=set:{{ range.label }},{{ range.start_v4 }},static,{{ (range.start_v4 + "/" + range.prefix_length_v4 | default(24) | string) | ansible.utils.ipaddr('netmask') }},{{ range.ttl | default('1h') }}
{% if range.domain is defined and range.domain | length > 0 -%}
domain={{ range.domain }},{{ range.start_v4 }}/{{ range.prefix_length_v4 | default('24') }},local
{% endif %}
{% endif %}
{% if range.start_v6 is defined and range.start_v6 | length > 0 %}
{% if range.start_v6 is defined and range.start_v6 | length > 0 -%}
dhcp-range=set:{{ range.label }},{{ range.start_v6 }},static,{{ range.prefix_length_v6 | default('64') }},{{ range.ttl | default('1h') }}
{% if range.domain is defined and range.domain | length > 0 -%}
domain={{ range.domain }},{{ range.start_v6 }}/{{ range.prefix_length_v6 | default('64') }},local
{% endif %}
{% endif %}
{% for option in range['options'] | default([]) %}
{% for option in range['options'] | default([]) -%}
dhcp-option=tag:{{ range.label }},{{ option }}
{% endfor %}
{% for option in range['options_force'] | default([]) %}
{% for option in range['options_force'] | default([]) -%}
dhcp-option-force=tag:{{ range.label }},{{ option }}
{% endfor %}
{% endfor %}
Expand Down

0 comments on commit e2750f9

Please sign in to comment.