Merge pull request #18 from corvus-migratorius/add-dnsmasq

Add dnsmasq
This commit is contained in:
Fogucoco
2025-12-12 10:40:30 +03:00
committed by GitHub
19 changed files with 235 additions and 0 deletions

View File

@@ -7,3 +7,4 @@ loop_var_prefix: "^(__|{role}_)"
exclude_paths:
- .github/
- .ansible/

View File

@@ -0,0 +1,16 @@
---
profile: production
strict: true
# Enable checking of loop variable prefixes in roles
loop_var_prefix: "^(__|{role}_)"
skip_list:
- var-naming[no-role-prefix]
warn_list:
- role-name[path]
- var-naming[no-role-prefix]
exclude_paths:
- .github/

2
roles/dnsmasq/.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
.vscode
.idea

8
roles/dnsmasq/.yamllint Normal file
View File

@@ -0,0 +1,8 @@
---
rules:
brackets:
forbid: false
min-spaces-inside: 0
max-spaces-inside: 2
min-spaces-inside-empty: -1
max-spaces-inside-empty: 2

37
roles/dnsmasq/README.md Normal file
View File

@@ -0,0 +1,37 @@
ansible-dnsmasq
=========
Deploy dnsmasq on the target node. For now, supports only DNS functionality (DHCP and TFTP are not configuratble).
Requirements
------------
Take care to open the port you choose for dnsmasq to serve queries on. This role does not handle firewall configuration.
Role Variables
--------------
None
Dependencies
------------
None
Example Playbook
----------------
```yaml
roles:
- role: genlab.dnsmasq
```
License
-------
BSD
Author Information
------------------
corvus-migratorius@proton.me

View File

@@ -0,0 +1,11 @@
---
name: ansible-dnsmasq
channels:
- conda-forge
dependencies:
- python~=3.12.0
- pip>=24.2
- actionlint
- pip:
- -r requirements.txt
- -r requirements.ci.txt

View File

@@ -0,0 +1,9 @@
---
name: ansible-dnsmasq
channels:
- conda-forge
dependencies:
- python~=3.12.0
- pip>=24.2
- pip:
- -r requirements.txt

View File

@@ -0,0 +1,3 @@
---
dnsmasq_cache_size: 100
dnsmasq_dns_port: 5300

View File

@@ -0,0 +1,7 @@
---
- name: "Restart dnsmasq"
ansible.builtin.systemd_service:
name: dnsmasq
state: restarted
daemon_reload: true
enabled: true

View File

@@ -0,0 +1,17 @@
---
galaxy_info:
role_name: dnsmasq
namespace: genlab
author: "Alexander Gorelyshev"
company: "Genlab, LLC"
description: ""
license: "MIT"
min_ansible_version: "2.1"
platforms:
- name: "Ubuntu"
versions: ["focal", "jammy"]
galaxy_tags: []
dependencies: []

View File

@@ -0,0 +1,21 @@
---
- name: Converge
hosts: all
roles:
- role: genlab.common.ufw
disable_ipv6: true
rules:
- rule: allow
# proto: udp
port: 5300
interface: lo
direction: in
comment: "Allow dnsmasq to serve DNS queries on the given interface"
- role: genlab.common.dnsmasq
dnsmasq_iface: lo
dnsmasq_domain: adm.local
dnsmasq_dns_port: 5300
dnsmasq_nodes:
- name: hub
ip: 127.0.0.1

View File

@@ -0,0 +1,27 @@
---
dependency:
name: galaxy
driver:
name: docker
platforms:
- name: ubuntu
image: geerlingguy/docker-${MOLECULE_DISTRO:-ubuntu2204}-ansible:latest
pre_build_image: true
command: ${MOLECULE_DOCKER_COMMAND:-""}
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
cgroupns_mode: host
privileged: true
provisioner:
name: ansible
verifier:
name: ansible
lint: |
set -e
yamllint .
ansible-lint .

View File

@@ -0,0 +1,19 @@
---
- name: Verify
hosts: all
gather_facts: false
any_errors_fatal: true
pre_tasks:
- name: "Install a package providing the `dig` tool"
ansible.builtin.apt:
name: dnsutils
state: present
tasks:
- name: "Test the output of the `dig` command"
changed_when: false
register: dnsmasq_dig
failed_when: 'dnsmasq_dig.stdout != "127.0.0.1"'
ansible.builtin.command:
cmd: "dig @127.0.0.1 -p 5300 hub.adm.local +short"

View File

@@ -0,0 +1,6 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": [
"config:recommended"
]
}

View File

@@ -0,0 +1,6 @@
ansible-lint
molecule==24.12.0
molecule-plugins[docker]
docker~=7.1.0
requests==2.31.0 # pinned to the latest version not breaking Docker SDK
yamllint

View File

@@ -0,0 +1 @@
ansible~=11.1.0

View File

@@ -0,0 +1,5 @@
# requirements file
---
roles:
- name: genlab.ufw
src: https://github.com/corvus-migratorius/ansible-ufw.git

View File

@@ -0,0 +1,38 @@
---
- name: "Install dnsmasq"
ansible.builtin.apt:
name: dnsmasq
state: present
update_cache: true
- name: "Create interface-specific configuration file"
notify: "Restart dnsmasq"
ansible.builtin.blockinfile:
path: /etc/dnsmasq.d/{{ dnsmasq_domain }}.conf
create: true
owner: root
group: root
mode: "0660"
block: |
interface="{{ dnsmasq_iface }}"
port="{{ dnsmasq_dns_port }}"
cache-size="{{ dnsmasq_cache_size }}"
log-queries
server=1.1.1.1 # Cloudflare DNS
server=8.8.8.8 # Google DNS
server=8.8.4.4 # Google DNS (secondary)
- name: "Add dnsmasq_nodes to the configuration file"
notify: "Restart dnsmasq"
loop: "{{ dnsmasq_nodes }}"
ansible.builtin.blockinfile:
path: /etc/dnsmasq.d/{{ dnsmasq_domain }}.conf
marker: "# {mark} ANSIBLE MANAGED: {{ item.name }}.{{ dnsmasq_domain }}"
block: |
address=/{{ item.name }}.{{ dnsmasq_domain }}/{{ item.ip }}
- name: "Flush handlers"
ansible.builtin.meta: flush_handlers

View File

@@ -0,0 +1 @@
---