Skip to content

Commit

Permalink
Merge pull request #19 from atosatto/f-freakyexperiments
Browse files Browse the repository at this point in the history
Role refactoring to address #11
  • Loading branch information
atosatto authored Nov 9, 2016
2 parents a579dbe + ae90e98 commit c3ba3de
Show file tree
Hide file tree
Showing 26 changed files with 365 additions and 290 deletions.
12 changes: 8 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# Created by https://www.gitignore.io/api/vim,linux

### Vim ###
[._]*.s[a-w][a-z]
[._]s[a-w][a-z]
Expand All @@ -8,7 +6,6 @@ Session.vim
.netrwhist
*~


### Linux ###
*~

Expand All @@ -18,6 +15,13 @@ Session.vim
# Linux trash folder which might appear on any partition or disk
.Trash-*

# test-kitchen related
### Ansible ###
*.retry

### Test-Kitchen ###
.kitchen/
.kitchen.local.yml

### Molecule ###
.vagrant/
.molecule/
178 changes: 102 additions & 76 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,98 +1,124 @@
PowerDNS Recursor Role
======================

An Ansible role created by the folks behind PowerDNS to install and configure
the PowerDNS Recursor.

This role is considered alpha quality at the moment, issues and pull requests
are accepted.

Requirements
------------

An Ansible 2.0 or higher installation.

Dependencies
------------

This role depends on [`atosatto.package-extras`](https://galaxy.ansible.com/atosatto/package-extras/).
See the `requirements.yml` file for further details.

Role Variables
--------------
### pdns_rec_config
A dict detailing the configuration of PowerDNS. You should not set the following
options here (other variables set these):
* config-dir
* set-uid
* set-gid

### pdns_rec_config_dir
The directory where the configuration (`recursor.conf`) is stored. '/etc/powerdns'
by default.

### pdns_rec_installation_type
How to install the PowerDNS Recursor, either 'packages', 'source' or 'url'.
'packages' by default. Source installations are not supported yet.

### pdns_rec_repo_provider
When using 'packages' for pdns_rec_installation_type, use operating system packages
('os') or the PowerDNS repository ('powerdns'). This is 'os' by default.

### pdns_rec_repo_branch
When installing from the PowerDNS repository, what branch should be installed?
Currently only 'master' and '40' (latest 4.0.x release) are supported.

### pdns_rec_url
When `pdns_rec_installation_type` is 'url'. This is the URL to be fetched for the
package.

### pdns_rec_url_checksum
When `pdns_rec_installation_type` is 'url'. This is the checksum of the package
that is fetched from `pdns_rec_url` This should be in the format for the `checksum`
option of the [`get_url module`](http://docs.ansible.com/ansible/get_url_module.html).

### pdns_rec_user
The user to run the PowerDNS Recursor as, this is 'pdns' by default on Debian
systems and 'pdns-recursor' on CentOS/RHEL. This user is not created.

### pdns_rec_group
The group to run the PowerDNS Recursor as, this is 'pdns' by default on Debian
systems and 'pdns-recursor' on CentOS/RHEL. This group is not created.

### pdns_rec_lua_config_file_content
The content for the lua-config-file. This will place a file called `config.lua`
in [pdns_rec_config_dir](#pdns_rec_config_dir) and add the configuration to
`recursor.conf`.

### pdns_rec_lua_dns_script_content
The content for the lua-dns-script. This will place a file called `dns-script.lua`
in [pdns_rec_config_dir](#pdns_rec_config_dir) and add the configuration to load
this script to `recursor.conf`.
Available variables are listed below, along with default values (see `defaults/main.yml`):

pdns_rec_install_repo: False

By default the PowerDNS Recursor is installed from the os default repositories.
You can install the PowerDNS Recursor package from official PowerDNS repository
overriding the `pdns_rec_install_repo` variable value as follows:

# Install the PowerDNS Recursor from the 'master' branch
- hosts: pdns-recursors-master
roles:
- { role: PowerDNS.pdns_recursor,
pdns_rec_install_repo: "{{ pdns_rec_official_pdns_master }}"

# Install the PowerDNS Recursor from the '40' branch
- hosts: pdns-recursors-40
roles:
- { role: PowerDNS.pdns_recursor,
pdns_rec_install_repo: "{{ pdns_rec_official_pdns_40 }}"

The roles also supports custom repositories

- hosts: all
vars:
pdns_rec_install_repo:
apt_repo_origin: "my.repo.com" # used to pin the pdns-recursor to the provided PowerDNS repository
apt_repo: "deb http://my.repo.com/{{ ansible_distribution | lower }} {{ ansible_distribution_release | lower }}/pdns-recursor main"
gpg_key: "http://my.repo.com/MYREPOGPGPUBKEY.asc" # repository public GPG key
gpg_key_id: "MYREPOGPGPUBKEYID" # to avoid to reimport the key each time the role is executed
yum_repo_baseurl: "http://my.repo.com/centos/$basearch/$releasever/pdns-recursor"
yum_repo_name: "powerdns-rec" # used to select only the pdns-recursor packages coming from this repo
roles:
- { role: PowerDNS.pdns_recursor }

If targetting a specific platform (e.g. Debian) is not needed to provide yum repositories informations.

pdns_rec_user: pdns # pdns-recursor on CentOS/RHEL
pdns_rec_group: pdns # pdns-recursor on CentOS/RHEL

The user and group the PowerDNS Recursor will run as.
**NOTE**: This role does not create any user or group as we assume that they're created
by the package or other roles.

pdns_rec_config_dir: "/etc/powerdns"
pdns_rec_config_lua: "{{ pdns_rec_config_dir }}/config.lua"
pdns_rec_config_dns_script: "{{ pdns_rec_config_dir }}/dns-script.lua"

The PowerDNS Recursor configuration files and directories.

pdns_rec_config: { }

A dict containing in YAML format the custom configuration of PowerDNS Recursor.
**NOTE**: You should not set the `config-dir`, `set-uid` and `set-gid` because are set by other role variables (respectively `pdns_rec_config_dir`, `pdns_rec_user`, `pdns_rec_group`).

# pdns_rec_lua_config_file_content: ""

String containing the content of the lua-config-file file.
This will create a file called `config.lua` into the `pdns_rec_config_dir`
and add the configuration to the `recursor.conf` configuration file.

# pdns_rec_lua_dns_script_content: ""

String containing the content of the lua-dns-script file.
This will create a file called `dns-script.lua` into the `pdns_rec_config_dir`
and add the configuration to load this script to the `recursor.conf`
configuration file.

Example Playbook
----------------
Bind to 203.0.113.53, port 5300 and allow only traffic from the 198.51.100.0/24
subnet:
```
- hosts: rec.example.net
roles:
- role: PowerDNS.pdns_recursor
vars:
pdns_rec_config:
'allow-from': '198.51.100.0/24'
'local-address': '203.0.113.53:5300'
```

Here we show some examples of usage of the `PowerDNS.pdns_recursor` role.

Bind to `203.0.113.53` on port `5300` and allow only traffic from the `198.51.100.0/24` subnet:

- hosts: pdns-recursors
vars:
pdns_rec_config:
'allow-from': '198.51.100.0/24'
'local-address': '203.0.113.53:5300'
roles:
- { role: PowerDNS.pdns_recursor }

Allow from multiple networks:
```
- hosts: rec.example.net
roles:
- role: PowerDNS.pdns_recursor
vars:
pdns_rec_config:
'allow-from':
- '198.51.100.0/24'
- '203.0.113.53/24'
'local-address': '203.0.113.53:5300'
```

- hosts: pdns-recursors
vars:
pdns_rec_config:
'allow-from':
- '198.51.100.0/24'
- '203.0.113.53/24'
'local-address': '203.0.113.53:5300'
roles:
- { role: PowerDNS.pdns_recursor }


License
-------

GPLv2

Author Information
------------------
Authors Informations
--------------------

Pieter Lexis <[email protected]>
Andrea Tosatto <[email protected]>
71 changes: 53 additions & 18 deletions defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,31 +1,66 @@
---
pdns_rec_installation_type: packages
pdns_rec_repo_provider: os

# Install packages from the master powerdns repo by default
pdns_rec_repo_branch: master

# Used when pdns_rec_installation_type is 'url'
pdns_rec_url: ''
pdns_rec_url_checksum: ''
# By default the PowerDNS Recursor is installed from the os default repositories.
pdns_rec_install_repo: False
#
# You can install the PowerDNS Recursor package from the 'master' branch as
# follows:
# - hosts: all
# roles:
# - { role: PowerDNS.pdns_recursor,
# pdns_rec_install_repo: "{{ pdns_rec_official_pdns_master }}"
#
# To install the PowerDNS Recursor package from the '40' branch of
# the PowerDNS official repository use the following playbook
# - hosts: all
# roles:
# - { role: PowerDNS.pdns_recursor,
# pdns_rec_install_repo: "{{ pdns_rec_official_pdns_40 }}"
#
# To install the PowerDNS Recursor package from a custom repository
# override the `pdns_rec_install_repo` default value in your playbook.
# e.g.
# - hosts: all
# vars:
# pdns_rec_install_repo:
# apt_repo_origin: "my.repo.com" # used to pin the pdns-recursor to the provided PowerDNS repository
# apt_repo: "deb http://my.repo.com/{{ ansible_distribution | lower }} {{ ansible_distribution_release | lower }}/pdns-recursor main"
# gpg_key: "http://my.repo.com/MYREPOGPGPUBKEY.asc" # repository public GPG key
# gpg_key_id: "MYREPOGPGPUBKEYID" # to avoid to reimport the key each time the role is executed
# yum_repo_baseurl: "http://my.repo.com/centos/$basearch/$releasever/pdns-recursor"
# yum_repo_name: "powerdns-rec" # used to select only the pdns-recursor packages coming from this repo
# roles:
# - { role: PowerDNS.pdns_recursor }

# The user and group to run as.
# NOTE: at the moment, we don't create a user as we assume the package creates
# a "pdns" user and group. If you change these variables, make sure to create
# the user and groups before applying this role
# The user and group the PowerDNS Recursor will run as.
# NOTE: This role does not create any user as we assume the "pdns" user and group
# to be created by the PowerDNS Recursor package or by an other role.
# If you change these variables, make sure to create the user and groups before
# applying this role
pdns_rec_user: pdns
pdns_rec_group: pdns

# The directory where the config is located
pdns_rec_config_dir: '/etc/powerdns'
# Configuration directory and files
pdns_rec_config_dir: "/etc/powerdns"
pdns_rec_config_lua: "{{ pdns_rec_config_dir }}/config.lua"
pdns_rec_config_dns_script: "{{ pdns_rec_config_dir }}/dns-script.lua"

# pdns_rec_config: A dict containing all configuration options, except for the
# "config-dir", "setuid" and "setgid" directives.
# NOTE: Right now, we don't verify the options when configuring the server.
# Dict containing all configuration options, except for the
# "config-dir", "setuid" and "setgid" directives in YAML format.
pdns_rec_config: { }
#
# Example:
# pdns_rec_config:
# allow_from: '127.0.0.1/8,192.168.2.0/24'
# local-address: 0.0.0.0
# server-id: 'nothing to see here'
pdns_rec_config: {}

# String containing the content of the lua-config-file file.
# NOTE: This will create a file called `config.lua` into the `pdns_rec_config_dir`
# and add the configuration to the `recursor.conf` configuration file.
# pdns_rec_lua_config_file_content: ""

# String containing the content of the lua-dns-script file.
# This will create a file called `dns-script.lua` into the `pdns_rec_config_dir`
# and add the configuration to load this script to the `recursor.conf`
# pdns_rec_lua_dns_script_content: ""
3 changes: 0 additions & 3 deletions files/pdns.pin

This file was deleted.

1 change: 1 addition & 0 deletions handlers/main.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
---

- name: Restart PowerDNS Recursor
service:
name: pdns-recursor
Expand Down
10 changes: 7 additions & 3 deletions meta/main.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---

galaxy_info:
author: Pieter Lexis
author: PowerDNS Engineering Team
description: PowerDNS Recursor Role
company: PowerDNS.COM BV
license: GPLv2
Expand All @@ -16,11 +16,15 @@ galaxy_info:
- name: Ubuntu
versions:
- trusty
- utopic
- vivid
- wily
- xenial
galaxy_tags:
- system
- pdns
- powerdns
- pdns-recursor
- powerdnsrecursor
dependencies: []

dependencies:
- { role: atosatto.packages-extras }
34 changes: 34 additions & 0 deletions molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---

ansible:
requirements_file: requirements.yml
# verbose: true

driver:
name: vagrant

vagrant:

platforms:
- name: centos-7
box: centos/7
- name: ubuntu-xenial
box: bento/ubuntu-16.04
- name: debian-jessie
box: debian/jessie64

providers:
- name: virtualbox
type: virtualbox
options:
memory: 1024
cpus: 2

instances:
- name: pdns-recursor-01
interfaces:
- network_name: private_network
type: dhcp
auto_config: true
options:
append_platform_to_hostname: yes
Loading

0 comments on commit c3ba3de

Please sign in to comment.