Skip to content

Commit

Permalink
add ansible and docker files
Browse files Browse the repository at this point in the history
  • Loading branch information
lightlike committed Jun 17, 2024
1 parent df28ff1 commit ec245ea
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 163 deletions.
162 changes: 0 additions & 162 deletions .gitignore

This file was deleted.

25 changes: 25 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
FROM docker.io/alpine:3.20

RUN apk add --no-cache \
ca-certificates \
openssh \
git \
ansible \
make \
just \
py3-dnspython \
py3-passlib

ENV ANSIBLE_STDOUT_CALLBACK=unixy
ENV ANSIBLE_LOAD_CALLBACK_PLUGINS=1
ENV RECORDS="* @"
ENV SCHEDULE="*/10 * * * *"

WORKDIR /netcup-dns

COPY ansible/update-dns.yaml ansible
COPY entrypoint.sh .
RUN chmod +x entrypoint.sh

ENTRYPOINT [ "entrypoint.sh" ]
CMD [ "crond", "-f" ]
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2024 DanielN
Copyright (c) 2024 lightlike

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
65 changes: 65 additions & 0 deletions ansible/update-dns.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
---
- hosts: 127.0.0.1
connection: local
vars:
data_base_path: "/tmp/netcup-dns"
ipv4_path: "{{ data_base_path }}/IPv4"
ipv6_path: "{{ data_base_path }}/IPv6"

tasks:
- name: Create netcup directory if it does not exist
ansible.builtin.file:
path: "{{ data_base_path }}"
state: directory

- name: Get IPv4
vars:
do_check: "{{ lookup('env','IPv4') }}"
when: do_check != 'no'
ignore_errors: yes
ansible.builtin.get_url:
url: "{{ item }}"
dest: "{{ ipv4_path }}"
with_items:
- http://v4.ident.me/
- http://v4.tnedi.me/
register: result_v4

- name: Get IPv6
vars:
do_check: "{{ lookup('env','IPv6') }}"
when: do_check != 'no'
ignore_errors: yes
ansible.builtin.get_url:
url: "{{ item }}"
dest: "{{ ipv6_path }}"
with_items:
- http://v6.ident.me/
- http://v6.tnedi.me/
register: result_v6

- name: Create IPv4 Record
when: result_v4.changed
ignore_errors: yes
community.general.netcup_dns:
api_key: "{{ lookup('env','API_KEY') }}"
api_password: "{{ lookup('env','API_PASSWORD') }}"
customer_id: "{{ lookup('env','CUSTOMER_ID') }}"
domain: "{{ lookup('env','DOMAIN') }}"
record: "{{ item }}"
type: "A"
value: "{{ lookup('file', ipv4_path) }}"
with_items: "{{ lookup('env','RECORDS') | split }}"

- name: Create IPv6 Record
when: result_v6.changed
ignore_errors: yes
community.general.netcup_dns:
api_key: "{{ lookup('env','API_KEY') }}"
api_password: "{{ lookup('env','API_PASSWORD') }}"
customer_id: "{{ lookup('env','CUSTOMER_ID') }}"
domain: "{{ lookup('env','DOMAIN') }}"
record: "{{ item }}"
type: "A"
value: "{{ lookup('file', ipv6_path) }}"
with_items: "{{ lookup('env','RECORDS') | split }}"
3 changes: 3 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
echo "${SCHEDULE} ansible-playbook /netcup-dns/update-dns.yaml" > /etc/crontabs/root
exec "$@"

0 comments on commit ec245ea

Please sign in to comment.