feat: initial commit

This commit is contained in:
Simon Cornet 2025-07-14 14:19:39 +02:00
commit f8ec658b1a
18 changed files with 328 additions and 93 deletions

23
.ansible-lint Normal file
View file

@ -0,0 +1,23 @@
---
exclude_paths:
- ".gitlab/*"
- ".gitlab-ci.yml"
- "defaults/main.yaml"
- "meta/main.yaml"
- "vars/*"
kinds:
- playbook: "**/*.{yml,yaml}"
skip_list:
- "command-shell"
- "experimental"
- "git-latest"
- "no-changed-when"
- "no-handler"
- "name[casing]"
- "name[template]"
- "risky-file-permissions"
- "schema[playbook]"
- "var-naming[no-role-prefix]"

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
.ansible

22
.gitlab-ci.yml Normal file
View file

@ -0,0 +1,22 @@
---
# gitLab ci stages
stages:
# deployment
- "gitleaks"
- "linting"
- "deployment"
# include jobs
include:
# deployment
- local: ".gitlab/gitleaks.yaml"
- local: ".gitlab/deployment.yaml"
# linting
- component: "$CI_SERVER_FQDN/components/ansible/linting@v2.0.1"
- component: "$CI_SERVER_FQDN/components/markdownlint/markdownlint@1.0.0"
- component: "$CI_SERVER_FQDN/components/yamllint/yamllint@1.0.2"

32
.gitlab/deployment.yaml Normal file
View file

@ -0,0 +1,32 @@
---
# deploy ansible/roles/common code
deployment:
stage: "deployment"
image:
name: "cr.simoncor.net/siempie/ssh-client:v25.06.03"
entrypoint: ["/bin/sh", "-c"]
rules:
# run only on push to default branch
- if: '$CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
- when: "never"
# prepare ssh
before_script:
# prepare ssh
- |
# prepare ssh
mkdir -p ~/.ssh
chmod 700 ~/.ssh
echo "$SSH_CONFIG" > ~/.ssh/config
echo "$SSH_DEPLOYMENT_KEY" > ~/.ssh/id_ed25519
chmod 600 ~/.ssh/id_ed25519
# deployment commands
script:
- |
# install ansible roles dependancies
ssh $SSH_DEPLOYMENT_USER@$ANSIBLE_SERVER \
"sudo /usr/local/bin/ansible-galaxy install -r /etc/ansible/roles/requirements.yaml --force"

18
.gitlab/gitleaks.yaml Normal file
View file

@ -0,0 +1,18 @@
---
# gitleaks
gitleaks:
stage: "gitleaks"
image:
name: "ghcr.io/gitleaks/gitleaks:latest"
variables:
GIT_DEPTH: 1
rules:
# run only on push to default branch
- if: '$CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
- when: "never"
# start linting
script:
- "gitleaks detect --source . --verbose --redact"

12
.markdownlint-cli2.jsonc Normal file
View file

@ -0,0 +1,12 @@
{
// files to lint
"globs": [
"readme.md"
],
// linting rules
"config": {
"MD013": {
"line_length": 120
}
}
}

30
.yamllint Normal file
View file

@ -0,0 +1,30 @@
---
extends: 'default'
rules:
braces:
max-spaces-inside: 1
forbid: true
comments:
min-spaces-from-content: 1
comments-indentation: false
empty-lines:
max: 2
indentation:
spaces: 2
check-multi-line-strings: true
line-length:
max: 120
allow-non-breakable-words: true
allow-non-breakable-inline-mappings: true
new-line-at-end-of-file: 'enable'
octal-values:
forbid-implicit-octal: true
forbid-explicit-octal: true
truthy:
allowed-values:
- 'true'
- 'false'
quoted-strings:
quote-type: 'any'
required: true

View file

@ -1,93 +0,0 @@
# ans-unbound
## Getting started
To make it easy for you to get started with GitLab, here's a list of recommended next steps.
Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)!
## Add your files
- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files
- [ ] [Add files using the command line](https://docs.gitlab.com/topics/git/add_files/#add-files-to-a-git-repository) or push an existing Git repository with the following command:
```
cd existing_repo
git remote add origin https://gitlab.simoncor.net/ansible/ans-unbound.git
git branch -M main
git push -uf origin main
```
## Integrate with your tools
- [ ] [Set up project integrations](https://gitlab.simoncor.net/ansible/ans-unbound/-/settings/integrations)
## Collaborate with your team
- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/)
- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html)
- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/)
- [ ] [Set auto-merge](https://docs.gitlab.com/user/project/merge_requests/auto_merge/)
## Test and Deploy
Use the built-in continuous integration in GitLab.
- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/)
- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing (SAST)](https://docs.gitlab.com/ee/user/application_security/sast/)
- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html)
- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/)
- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)
***
# Editing this README
When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thanks to [makeareadme.com](https://www.makeareadme.com/) for this template.
## Suggestions for a good README
Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.
## Name
Choose a self-explaining name for your project.
## Description
Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
## Badges
On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.
## Visuals
Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
## Installation
Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.
## Usage
Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.
## Support
Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.
## Roadmap
If you have ideas for releases in the future, it is a good idea to list them in the README.
## Contributing
State if you are open to contributions and what your requirements are for accepting them.
For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.
You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.
## Authors and acknowledgment
Show your appreciation to those who have contributed to the project.
## License
For open source projects, say how it is licensed.
## Project status
If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.

23
defaults/main.yaml Normal file
View file

@ -0,0 +1,23 @@
---
# unbound upstream info
unbound_upstream_dns:
- "8.8.8.8"
- "1.1.1.1"
# unbound allow access
unbound_allow_access:
- name: "example-lan"
network: "192.168.1.0/24"
# unbound zones
unbound_zones:
# example.internal
- zone: "example.internal"
type: "static"
records:
- name: "server.example.internal"
type: "A"
value: "192.168.1.0"

9
handlers/main.yaml Normal file
View file

@ -0,0 +1,9 @@
---
# unbound
- name: "restart unbound"
ansible.builtin.systemd:
name: "unbound.service"
state: "restarted"
daemon_reload: true
enabled: true

8
meta/main.yaml Normal file
View file

@ -0,0 +1,8 @@
---
galaxy_info:
author: "siempie"
description: "install and configure an unbound server"
license: "MIT"
role_name: "unbound"
dependencies: []

15
readme.md Normal file
View file

@ -0,0 +1,15 @@
# Overview
This role configures an Unbound DNS server.
## Supported Operating Systems
| Operating System | Version |
| --- | ----- |
| Debian | 12 |
## Tags
This role has no tags.

4
renovate.json Normal file
View file

@ -0,0 +1,4 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": [ "local>cicd/renovate:ansible" ]
}

12
tasks/config.yaml Normal file
View file

@ -0,0 +1,12 @@
---
# configure unbound
- name: "config - unbound"
ansible.builtin.template:
src: "{{ item }}"
dest: "/etc/unbound/unbound.conf.d/"
owner: "root"
group: "root"
mode: "0644"
with_fileglob: "templates/unbound/*.j2"
notify: "restart unbound"

7
tasks/install.yaml Normal file
View file

@ -0,0 +1,7 @@
---
# install unbound
- name: "install unbound"
ansible.builtin.apt:
name: "unbound"
when: 'ansible_os_family == "Debian"'

9
tasks/main.yaml Normal file
View file

@ -0,0 +1,9 @@
---
# import install
- name: "install"
ansible.builtin.import_tasks: "install.yaml"
# import config
- name: "config"
ansible.builtin.import_tasks: "config.yaml"

View file

@ -0,0 +1,40 @@
server:
verbosity: 1
interface: 0.0.0.0
port: 53
do-ip4: yes
do-ip6: yes
do-udp: yes
do-tcp: no
# access control
{% for network in unbound_allow_access % }
## {{ network.name }}
access-control: {{ network.network }} allow
{% endfor %}
# security and performance
cache-max-ttl: 86400
cache-min-ttl: 3600
harden-dnssec-stripped: yes
harden-glue: yes
hide-identity: yes
hide-version: yes
infra-cache-slabs: 8
key-cache-slabs: 8
msg-cache-slabs: 8
num-threads: 2
prefetch: yes
rrset-cache-slabs: 8
use-caps-for-id: no
# include zone configurations
include: "/etc/unbound/conf.d/*.conf"
# forward zones configuration
forward-zone:
name: "."
{% for dns_server in unbound_upstream_dns %}
forward-addr: {{ dns_server }}
{% endfor %}

View file

@ -0,0 +1,63 @@
{% for zone in unbound_zones %}
# zone: {{ zone.zone }}
server:
local-zone: "{{ zone.zone }}." {{ zone.type | default('static') }}
{% for record in zone.records %}
{% if record.type == 'MX' %}
local-data: "{{ record.name }}. IN MX {{ record.priority }} {{ record.value }}"
{% elif record.type == 'CNAME' %}
local-data: "{{ record.name }}. IN CNAME {{ record.value }}"
{% elif record.type == 'TXT' %}
local-data: "{{ record.name }}. IN TXT \"{{ record.value }}\""
{% elif record.type == 'PTR' %}
local-data: "{{ record.name }}. IN PTR {{ record.value }}"
{% else %}
local-data: "{{ record.name }}. IN {{ record.type }} {{ record.value }}"
{% endif %}
{% endfor %}
{% endfor %}
{# generate reverse dns zones from a records #}
{% set reverse_zones = {} %}
{% for zone in unbound_zones %}
{% for record in zone.records %}
{% if record.type == 'A' %}
{% set ip_parts = record.value.split('.') %}
{% if ip_parts[0] == '192' and ip_parts[1] == '168' %}
{% set reverse_zone = ip_parts[2] + '.168.192.in-addr.arpa' %}
{% set reverse_record = ip_parts[3] + '.' + reverse_zone %}
{% if reverse_zone not in reverse_zones %}
{% set _ = reverse_zones.update({reverse_zone: []}) %}
{% endif %}
{% set _ = reverse_zones[reverse_zone].append({'ptr': reverse_record, 'hostname': record.name}) %}
{% elif ip_parts[0] == '10' and ip_parts[1] == '8' %}
{% set reverse_zone = '8.10.in-addr.arpa' %}
{% set reverse_record = ip_parts[3] + '.' + ip_parts[2] + '.' + reverse_zone %}
{% if reverse_zone not in reverse_zones %}
{% set _ = reverse_zones.update({reverse_zone: []}) %}
{% endif %}
{% set _ = reverse_zones[reverse_zone].append({'ptr': reverse_record, 'hostname': record.name}) %}
{% elif ip_parts[0] == '10' and ip_parts[1] == '0' %}
{% set reverse_zone = '0.10.in-addr.arpa' %}
{% set reverse_record = ip_parts[3] + '.' + ip_parts[2] + '.' + reverse_zone %}
{% if reverse_zone not in reverse_zones %}
{% set _ = reverse_zones.update({reverse_zone: []}) %}
{% endif %}
{% set _ = reverse_zones[reverse_zone].append({'ptr': reverse_record, 'hostname': record.name}) %}
{% endif %}
{% endif %}
{% endfor %}
{% endfor %}
{% for reverse_zone, ptr_records in reverse_zones.items() %}
# reverse dns zone: {{ reverse_zone }}
server:
local-zone: "{{ reverse_zone }}." static
{% for ptr_record in ptr_records %}
local-data: "{{ ptr_record.ptr }}. IN PTR {{ ptr_record.hostname }}."
{% endfor %}
{% endfor %}