Skip to content

Commit 6afc841

Browse files
authored
Add support for local binary (#34)
[minor] Signed-off-by: Ben Kochie <[email protected]>
1 parent 52d3483 commit 6afc841

File tree

7 files changed

+183
-23
lines changed

7 files changed

+183
-23
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ All variables which can be overridden are stored in [defaults/main.yml](defaults
2020
| Name | Default Value | Description |
2121
| ---------------------------- | -------------- | -----------------------------------|
2222
| `coredns_version` | 1.6.6 | CoreDNS package version |
23+
| `coredns_binary_local_dir` | "" | Allows to use local packages instead of ones distributed on github. As parameter it takes a directory where `coredns` binary is stored on host on which ansible is ran. This overrides `coredns_version` parameter |
2324
| `coredns_dns_port` | 53 | Port on which CoreDNS will listen for DNS requests |
2425
| `coredns_config_file` | | This should contain path to file with coredns configuration [Corefile](https://coredns.io/manual/toc/#configuration) |
2526

defaults/main.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ coredns_dns_port: 53
44

55
# Config file name, searched in ansible templates path.
66
coredns_config_file: ""
7+
8+
# Use a local binary instead of the official release.
9+
coredns_binary_local_dir: ""

molecule/alternative/molecule.yml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
---
2+
dependency:
3+
name: galaxy
4+
driver:
5+
name: docker
6+
lint:
7+
name: yamllint
8+
platforms:
9+
- name: bionic
10+
image: quay.io/paulfantom/molecule-systemd:ubuntu-18.04
11+
docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}"
12+
privileged: true
13+
volumes:
14+
- /sys/fs/cgroup:/sys/fs/cgroup:ro
15+
- name: xenial
16+
image: quay.io/paulfantom/molecule-systemd:ubuntu-16.04
17+
docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}"
18+
privileged: true
19+
volumes:
20+
- /sys/fs/cgroup:/sys/fs/cgroup:ro
21+
- name: stretch
22+
image: quay.io/paulfantom/molecule-systemd:debian-9
23+
docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}"
24+
privileged: true
25+
volumes:
26+
- /sys/fs/cgroup:/sys/fs/cgroup:ro
27+
- name: buster
28+
image: quay.io/paulfantom/molecule-systemd:debian-10
29+
docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}"
30+
privileged: true
31+
volumes:
32+
- /sys/fs/cgroup:/sys/fs/cgroup:ro
33+
- name: centos7
34+
image: quay.io/paulfantom/molecule-systemd:centos-7
35+
docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}"
36+
privileged: true
37+
volumes:
38+
- /sys/fs/cgroup:/sys/fs/cgroup:ro
39+
- name: centos8
40+
image: quay.io/paulfantom/molecule-systemd:centos-8
41+
docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}"
42+
privileged: true
43+
volumes:
44+
- /sys/fs/cgroup:/sys/fs/cgroup:ro
45+
groups:
46+
- python3
47+
- name: fedora
48+
image: quay.io/paulfantom/molecule-systemd:fedora-30
49+
docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}"
50+
privileged: true
51+
volumes:
52+
- /sys/fs/cgroup:/sys/fs/cgroup:ro
53+
groups:
54+
- python3
55+
provisioner:
56+
name: ansible
57+
lint:
58+
name: ansible-lint
59+
playbooks:
60+
create: ../default/create.yml
61+
prepare: prepare.yml
62+
converge: playbook.yml
63+
destroy: ../default/destroy.yml
64+
inventory:
65+
group_vars:
66+
python3:
67+
ansible_python_interpreter: /usr/bin/python3
68+
scenario:
69+
name: alternative
70+
verifier:
71+
name: testinfra
72+
lint:
73+
name: flake8
74+
enabled: true

molecule/alternative/playbook.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
- name: Run role
3+
hosts: all
4+
any_errors_fatal: true
5+
roles:
6+
- ansible-coredns
7+
vars:
8+
coredns_binary_local_dir: "/tmp"
9+
coredns_config_file: "Corefile.example.j2"
10+
coredns_dns_port: 5300
11+
coredns_system_group: "different"
12+
coredns_system_user: "different"

molecule/alternative/prepare.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
- name: Prepare
3+
hosts: all
4+
gather_facts: false
5+
vars:
6+
go_arch: amd64
7+
coredns_version: 1.6.6
8+
tasks:
9+
- name: Download coredns binary to local folder
10+
become: false
11+
get_url:
12+
url: "https://github.com/coredns/coredns/releases/download/v{{ coredns_version }}/coredns_{{ coredns_version }}_linux_{{ go_arch }}.tgz"
13+
dest: "/tmp/coredns_{{ coredns_version }}_linux_{{ go_arch }}.tgz"
14+
register: _download_binary
15+
until: _download_binary is succeeded
16+
retries: 5
17+
delay: 2
18+
run_once: true
19+
check_mode: false
20+
21+
- name: Unpack coredns binary
22+
become: false
23+
unarchive:
24+
src: "/tmp/coredns_{{ coredns_version }}_linux_{{ go_arch }}.tgz"
25+
dest: "/tmp"
26+
creates: "/tmp/coredns"
27+
run_once: true
28+
check_mode: false
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import os
2+
import testinfra.utils.ansible_runner
3+
4+
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
5+
os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all')
6+
7+
8+
def test_directories(host):
9+
dirs = [
10+
"/etc/coredns",
11+
"/etc/coredns/zones",
12+
]
13+
for dir in dirs:
14+
d = host.file(dir)
15+
assert d.is_directory
16+
assert d.exists
17+
18+
19+
def test_service(host):
20+
s = host.service("coredns")
21+
assert s.is_running
22+
23+
24+
def test_socket(host):
25+
sockets = [
26+
"udp://127.0.0.1:5300"
27+
]
28+
for socket in sockets:
29+
s = host.socket(socket)
30+
assert s.is_listening

tasks/install.yml

Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -26,37 +26,49 @@
2626
- /etc/coredns
2727
- /etc/coredns/zones
2828

29-
- name: Download coredns binary to local folder
30-
become: false
31-
get_url:
32-
url: "https://github.com/coredns/coredns/releases/download/v{{ coredns_version }}/coredns_{{ coredns_version }}_linux_{{ go_arch }}.tgz"
33-
dest: "/tmp/coredns_{{ coredns_version }}_linux_{{ go_arch }}.tgz"
34-
checksum: "sha256:{{ coredns_checksum }}"
35-
register: _download_binary
36-
until: _download_binary is succeeded
37-
retries: 5
38-
delay: 2
39-
delegate_to: localhost
40-
check_mode: false
29+
- block:
30+
- name: Download coredns binary to local folder
31+
become: false
32+
get_url:
33+
url: "https://github.com/coredns/coredns/releases/download/v{{ coredns_version }}/coredns_{{ coredns_version }}_linux_{{ go_arch }}.tgz"
34+
dest: "/tmp/coredns_{{ coredns_version }}_linux_{{ go_arch }}.tgz"
35+
checksum: "sha256:{{ coredns_checksum }}"
36+
register: _download_binary
37+
until: _download_binary is succeeded
38+
retries: 5
39+
delay: 2
40+
delegate_to: localhost
41+
check_mode: false
4142

42-
- name: Unpack coredns binary
43-
become: false
44-
unarchive:
45-
src: "/tmp/coredns_{{ coredns_version }}_linux_{{ go_arch }}.tgz"
46-
dest: "/tmp"
47-
creates: "/tmp/coredns"
48-
delegate_to: localhost
49-
check_mode: false
43+
- name: Unpack coredns binary
44+
become: false
45+
unarchive:
46+
src: "/tmp/coredns_{{ coredns_version }}_linux_{{ go_arch }}.tgz"
47+
dest: "/tmp"
48+
creates: "/tmp/coredns"
49+
delegate_to: localhost
50+
check_mode: false
5051

51-
- name: Propagate coredns binaries
52+
- name: Propagate coredns binaries
53+
copy:
54+
src: "/tmp/coredns"
55+
dest: "/usr/local/bin/coredns"
56+
mode: 0750
57+
owner: "{{ coredns_system_user }}"
58+
group: "{{ coredns_system_group }}"
59+
notify: restart coredns
60+
when: not ansible_check_mode
61+
when: coredns_binary_local_dir | length == 0
62+
63+
- name: propagate locally distributed coredns binary
5264
copy:
53-
src: "/tmp/coredns"
65+
src: "{{ coredns_binary_local_dir }}/coredns"
5466
dest: "/usr/local/bin/coredns"
5567
mode: 0750
5668
owner: "{{ coredns_system_user }}"
5769
group: "{{ coredns_system_group }}"
70+
when: coredns_binary_local_dir | length > 0
5871
notify: restart coredns
59-
when: not ansible_check_mode
6072

6173
- name: Copy the coredns systemd service file
6274
template:

0 commit comments

Comments
 (0)