summaryrefslogtreecommitdiff
path: root/roles/dyndns/server/tasks/main.yml
blob: c29d7eddce34852be8081d8804a8a9f9d754edd6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
---
- name: create user for dyndns
  user:
    name: dyndns
    home: /var/lib/dyndns
    system: yes
    shell: /bin/sh
    groups: bind

- name: create .ssh directory
  file:
    path: /var/lib/dyndns/.ssh
    state: directory
    mode: 0700
    owner: dyndns
    group: dyndns

- name: install zone update scripts
  loop:
  - dyndns.py
  - dyndns-regen.py
  template:
    src: "{{ item }}.j2"
    dest: "/usr/local/bin/{{ item }}"
    mode: 0755

- name: test if serial file exists
  stat:
    path: "/var/lib/dyndns/serial.{{ dyndns.domain }}"
  register: dyndns_serial_file_info

- name: autogenerate new serial
  when: not dyndns_serial_file_info.stat.exists
  copy:
    content: "{{ ansible_date_time.year }}{{ ansible_date_time.month }}{{ ansible_date_time.day }}00\n"
    dest: "/var/lib/dyndns/serial.{{ dyndns.domain }}"
    owner: dyndns
    group: dyndns

- name: generate header template
  template:
    src: header.tmpl.j2
    dest: "/var/lib/dyndns/header.{{ dyndns.domain }}"

- name: regenerate dns zone file if changed
  become: yes
  become_method: su
  become_user: dyndns
  command: /usr/local/bin/dyndns-regen.py "{{ dyndns.domain }}"
  register: dyndns_regen
  changed_when: "'OK: already up to date.' not in dyndns_regen.stdout"