add dnsmasq role
This commit is contained in:
@@ -7,3 +7,4 @@ loop_var_prefix: "^(__|{role}_)"
|
|||||||
|
|
||||||
exclude_paths:
|
exclude_paths:
|
||||||
- .github/
|
- .github/
|
||||||
|
- .ansible/
|
||||||
|
|||||||
16
roles/dnsmasq/.ansible-lint
Normal file
16
roles/dnsmasq/.ansible-lint
Normal 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
2
roles/dnsmasq/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
.vscode
|
||||||
|
.idea
|
||||||
8
roles/dnsmasq/.yamllint
Normal file
8
roles/dnsmasq/.yamllint
Normal 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
37
roles/dnsmasq/README.md
Normal 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
|
||||||
11
roles/dnsmasq/conda.dev.yml
Normal file
11
roles/dnsmasq/conda.dev.yml
Normal 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
|
||||||
9
roles/dnsmasq/conda.prod.yml
Normal file
9
roles/dnsmasq/conda.prod.yml
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
---
|
||||||
|
name: ansible-dnsmasq
|
||||||
|
channels:
|
||||||
|
- conda-forge
|
||||||
|
dependencies:
|
||||||
|
- python~=3.12.0
|
||||||
|
- pip>=24.2
|
||||||
|
- pip:
|
||||||
|
- -r requirements.txt
|
||||||
3
roles/dnsmasq/defaults/main.yml
Normal file
3
roles/dnsmasq/defaults/main.yml
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
---
|
||||||
|
cache_size: 100
|
||||||
|
dns_port: 5300
|
||||||
7
roles/dnsmasq/handlers/main.yml
Normal file
7
roles/dnsmasq/handlers/main.yml
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
---
|
||||||
|
- name: "Restart dnsmasq"
|
||||||
|
ansible.builtin.systemd_service:
|
||||||
|
name: dnsmasq
|
||||||
|
state: restarted
|
||||||
|
daemon_reload: true
|
||||||
|
enabled: true
|
||||||
17
roles/dnsmasq/meta/main.yml
Normal file
17
roles/dnsmasq/meta/main.yml
Normal 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: []
|
||||||
21
roles/dnsmasq/molecule/default/converge.yml
Normal file
21
roles/dnsmasq/molecule/default/converge.yml
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
---
|
||||||
|
- name: Converge
|
||||||
|
hosts: all
|
||||||
|
roles:
|
||||||
|
- role: genlab.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.dnsmasq
|
||||||
|
iface: lo
|
||||||
|
domain: adm.local
|
||||||
|
dns_port: 5300
|
||||||
|
nodes:
|
||||||
|
- name: hub
|
||||||
|
ip: 127.0.0.1
|
||||||
27
roles/dnsmasq/molecule/default/molecule.yml
Normal file
27
roles/dnsmasq/molecule/default/molecule.yml
Normal 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 .
|
||||||
19
roles/dnsmasq/molecule/default/verify.yml
Normal file
19
roles/dnsmasq/molecule/default/verify.yml
Normal 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: dig
|
||||||
|
failed_when: 'dig.stdout != "127.0.0.1"'
|
||||||
|
ansible.builtin.command:
|
||||||
|
cmd: "dig @127.0.0.1 -p 5353 hub.adm.vpn +short"
|
||||||
6
roles/dnsmasq/renovate.json
Normal file
6
roles/dnsmasq/renovate.json
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
|
||||||
|
"extends": [
|
||||||
|
"config:recommended"
|
||||||
|
]
|
||||||
|
}
|
||||||
6
roles/dnsmasq/requirements.ci.txt
Normal file
6
roles/dnsmasq/requirements.ci.txt
Normal 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
|
||||||
1
roles/dnsmasq/requirements.txt
Normal file
1
roles/dnsmasq/requirements.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
ansible~=11.1.0
|
||||||
5
roles/dnsmasq/requirements.yml
Normal file
5
roles/dnsmasq/requirements.yml
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
# requirements file
|
||||||
|
---
|
||||||
|
roles:
|
||||||
|
- name: genlab.ufw
|
||||||
|
src: https://github.com/corvus-migratorius/ansible-ufw.git
|
||||||
38
roles/dnsmasq/tasks/main.yml
Normal file
38
roles/dnsmasq/tasks/main.yml
Normal 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/{{ domain }}.conf
|
||||||
|
create: true
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
mode: "0660"
|
||||||
|
block: |
|
||||||
|
interface="{{ iface }}"
|
||||||
|
port="{{ dns_port }}"
|
||||||
|
cache-size="{{ 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 nodes to the configuration file"
|
||||||
|
notify: "Restart dnsmasq"
|
||||||
|
loop: "{{ nodes }}"
|
||||||
|
ansible.builtin.blockinfile:
|
||||||
|
path: /etc/dnsmasq.d/{{ domain }}.conf
|
||||||
|
marker: "# {mark} ANSIBLE MANAGED: {{ item.name }}.{{ domain }}"
|
||||||
|
block: |
|
||||||
|
address=/{{ item.name }}.{{ domain }}/{{ item.ip }}
|
||||||
|
|
||||||
|
|
||||||
|
- name: "Flush handlers"
|
||||||
|
ansible.builtin.meta: flush_handlers
|
||||||
1
roles/dnsmasq/vars/main.yml
Normal file
1
roles/dnsmasq/vars/main.yml
Normal file
@@ -0,0 +1 @@
|
|||||||
|
---
|
||||||
Reference in New Issue
Block a user