initial commit
commit
df2c03ee02
@ -0,0 +1,90 @@
|
||||
PRAGMA foreign_keys = 1;
|
||||
|
||||
CREATE TABLE domains (
|
||||
id INTEGER PRIMARY KEY,
|
||||
name VARCHAR(255) NOT NULL COLLATE NOCASE,
|
||||
master VARCHAR(128) DEFAULT NULL,
|
||||
last_check INTEGER DEFAULT NULL,
|
||||
type VARCHAR(6) NOT NULL,
|
||||
notified_serial INTEGER DEFAULT NULL,
|
||||
account VARCHAR(40) DEFAULT NULL
|
||||
);
|
||||
|
||||
CREATE UNIQUE INDEX name_index ON domains(name);
|
||||
|
||||
|
||||
CREATE TABLE records (
|
||||
id INTEGER PRIMARY KEY,
|
||||
domain_id INTEGER DEFAULT NULL,
|
||||
name VARCHAR(255) DEFAULT NULL,
|
||||
type VARCHAR(10) DEFAULT NULL,
|
||||
content VARCHAR(65535) DEFAULT NULL,
|
||||
ttl INTEGER DEFAULT NULL,
|
||||
prio INTEGER DEFAULT NULL,
|
||||
disabled BOOLEAN DEFAULT 0,
|
||||
ordername VARCHAR(255),
|
||||
auth BOOL DEFAULT 1,
|
||||
FOREIGN KEY(domain_id) REFERENCES domains(id) ON DELETE CASCADE ON UPDATE CASCADE
|
||||
);
|
||||
|
||||
CREATE INDEX records_lookup_idx ON records(name, type);
|
||||
CREATE INDEX records_lookup_id_idx ON records(domain_id, name, type);
|
||||
CREATE INDEX records_order_idx ON records(domain_id, ordername);
|
||||
|
||||
|
||||
CREATE TABLE supermasters (
|
||||
ip VARCHAR(64) NOT NULL,
|
||||
nameserver VARCHAR(255) NOT NULL COLLATE NOCASE,
|
||||
account VARCHAR(40) NOT NULL
|
||||
);
|
||||
|
||||
CREATE UNIQUE INDEX ip_nameserver_pk ON supermasters(ip, nameserver);
|
||||
|
||||
|
||||
CREATE TABLE comments (
|
||||
id INTEGER PRIMARY KEY,
|
||||
domain_id INTEGER NOT NULL,
|
||||
name VARCHAR(255) NOT NULL,
|
||||
type VARCHAR(10) NOT NULL,
|
||||
modified_at INT NOT NULL,
|
||||
account VARCHAR(40) DEFAULT NULL,
|
||||
comment VARCHAR(65535) NOT NULL,
|
||||
FOREIGN KEY(domain_id) REFERENCES domains(id) ON DELETE CASCADE ON UPDATE CASCADE
|
||||
);
|
||||
|
||||
CREATE INDEX comments_idx ON comments(domain_id, name, type);
|
||||
CREATE INDEX comments_order_idx ON comments (domain_id, modified_at);
|
||||
|
||||
|
||||
CREATE TABLE domainmetadata (
|
||||
id INTEGER PRIMARY KEY,
|
||||
domain_id INT NOT NULL,
|
||||
kind VARCHAR(32) COLLATE NOCASE,
|
||||
content TEXT,
|
||||
FOREIGN KEY(domain_id) REFERENCES domains(id) ON DELETE CASCADE ON UPDATE CASCADE
|
||||
);
|
||||
|
||||
CREATE INDEX domainmetaidindex ON domainmetadata(domain_id);
|
||||
|
||||
|
||||
CREATE TABLE cryptokeys (
|
||||
id INTEGER PRIMARY KEY,
|
||||
domain_id INT NOT NULL,
|
||||
flags INT NOT NULL,
|
||||
active BOOL,
|
||||
published BOOL DEFAULT 1,
|
||||
content TEXT,
|
||||
FOREIGN KEY(domain_id) REFERENCES domains(id) ON DELETE CASCADE ON UPDATE CASCADE
|
||||
);
|
||||
|
||||
CREATE INDEX domainidindex ON cryptokeys(domain_id);
|
||||
|
||||
|
||||
CREATE TABLE tsigkeys (
|
||||
id INTEGER PRIMARY KEY,
|
||||
name VARCHAR(255) COLLATE NOCASE,
|
||||
algorithm VARCHAR(50) COLLATE NOCASE,
|
||||
secret VARCHAR(255)
|
||||
);
|
||||
|
||||
CREATE UNIQUE INDEX namealgoindex ON tsigkeys(name, algorithm);
|
@ -0,0 +1,54 @@
|
||||
---
|
||||
- name: Install sqlite
|
||||
apt:
|
||||
name: sqlite3
|
||||
state: present
|
||||
|
||||
- name: Make sure pdns-user owns config-directory
|
||||
file:
|
||||
path: "{{ powerdns_config_directory }}"
|
||||
mode: 0775
|
||||
owner: pdns
|
||||
group: pdns
|
||||
state: directory
|
||||
|
||||
- name: Check if database file exists
|
||||
stat:
|
||||
path: "{{ powerdns_database_file }}"
|
||||
register: stat_database_file
|
||||
- block:
|
||||
- name: Upload database schema if sqlite3 database is not existing
|
||||
copy:
|
||||
src: "schema.sql"
|
||||
dest: "/tmp/powerdns_sqlite3_schema.sql"
|
||||
mode: 0600
|
||||
owner: "pdns"
|
||||
|
||||
- name: Template sqlite3 database
|
||||
shell: "sqlite3 {{ powerdns_database_file }} < /tmp/powerdns_sqlite3_schema.sql"
|
||||
become_user: "pdns"
|
||||
|
||||
- name: Delete uploaded database schema
|
||||
file:
|
||||
path: "/tmp/powerdns_sqlite3_schema.sql"
|
||||
state: absent
|
||||
when: not stat_database_file.stat.exists
|
||||
|
||||
- name: Check if TSIG key is in database
|
||||
command: "sqlite3 {{ powerdns_database_file }} \"SELECT * FROM tsigkeys WHERE name='{{ powerdns_tsig_key_name }}';\""
|
||||
changed_when: false
|
||||
register: sqlite3_command_tsig_key_check
|
||||
|
||||
- name: Add TSIG key to database
|
||||
command: "pdnsutil import-tsig-key {{ powerdns_tsig_key_name }} hmac-sha512 {{ powerdns_tsig_key }}"
|
||||
when: sqlite3_command_tsig_key_check.stdout | length == 0
|
||||
|
||||
- name: add supermaster entries
|
||||
command: "pdnsutil add-supermaster {{ item[0] }} {{ item[1] }}"
|
||||
ignore_errors: yes
|
||||
become: yes
|
||||
become_user: "pdns"
|
||||
with_nested:
|
||||
- "{{ powerdns_primary_ips }}"
|
||||
- "{{ powerdns_secondary_names }}"
|
||||
|
Loading…
Reference in New Issue