blob: 0391ac3e0e0b1b1682aaf18d8545cfdfc847f70e [file] [log] [blame]
Ivan Suzdal67bcad52017-05-26 18:45:54 +03001{%- from "powerdns/map.jinja" import server with context %}
2{%- from "powerdns/server/packages.jinja" import packages with context %}
3include:
4 - powerdns.server.service
5
Ivan Udovichenkoe25bced2018-08-07 12:52:46 +03006{%- if server.backend.get('use_socket', False) == True %}
7 {%- set mysql_connection_args = {
8 'use_socket': True,
9 'connection_charset': server.backend.get('dbcharset', 'utf8'),
10 'connection_db': server.backend.dbname,
11 'connection_default_file': server.backend.get('dbdefault_file', ''),
12 'connection_unix_socket': server.backend.socket,
13 'connection_user': server.backend.user,
14 'connection_pass': server.backend.password,
15 } %}
16{%- else %}
17 {%- set mysql_connection_args = {
18 'use_socket': False,
19 'connection_charset': server.backend.get('dbcharset', 'utf8'),
20 'connection_db': server.backend.dbname,
21 'connection_default_file': server.backend.get('dbdefault_file', ''),
22 'connection_host': server.backend.host,
23 'connection_port': server.backend.port,
24 'connection_user': server.backend.user,
25 'connection_pass': server.backend.password,
26 } %}
27{%- endif %}
28
Ivan Suzdal67bcad52017-05-26 18:45:54 +030029powerdns_mysql_packages:
30 pkg.installed:
31 - names: {{ packages.backends.mysql }}
32
Ivan Udovichenkoe25bced2018-08-07 12:52:46 +030033/etc/powerdns/dbtemplate.sql:
34 file.managed:
35 - source: salt://powerdns/files/mysql.sql
36 - require:
37 - pkg: powerdns_mysql_packages
38
Oleh Hryhorovf5949792018-10-09 11:00:37 +030039{%- set powerdns_db_tables = False %}
40
41{%- if grains.get('noservices') is not defined %}
Ivan Udovichenkoe25bced2018-08-07 12:52:46 +030042{%- set powerdns_db_tables = salt['mysql.db_tables'](server.backend.dbname, **mysql_connection_args) %}
Oleh Hryhorovf5949792018-10-09 11:00:37 +030043{%- endif %}
Ivan Udovichenkoe25bced2018-08-07 12:52:46 +030044{%- if not powerdns_db_tables %}
45powerdns_init_mysql_db:
46 mysql_query.run_file:
47 - database: {{ server.backend.dbname }}
48 - query_file: /etc/powerdns/dbtemplate.sql
49 - connection_charset: {{ mysql_connection_args.connection_charset }}
Oleh Hryhorovf5949792018-10-09 11:00:37 +030050 {%- if grains.get('noservices') %}
51 - onlyif: /bin/false
52 {%- endif %}
Ivan Udovichenkoe25bced2018-08-07 12:52:46 +030053{%- if mysql_connection_args.connection_default_file %}
54 - connection_default_file: {{ mysql_connection_args.connection_default_file }}
55{%- endif %}
56{%- if mysql_connection_args.use_socket == True %}
57 - connection_unix_socket: {{ mysql_connection_args.connection_unix_socket }}
58{%- else %}
59 - connection_host: {{ mysql_connection_args.connection_host }}
60 - connection_port: {{ mysql_connection_args.connection_port }}
61{%- endif %}
62 - connection_user: {{ mysql_connection_args.connection_user }}
63 - connection_pass: {{ mysql_connection_args.connection_pass }}
Ivan Udovichenkoe25bced2018-08-07 12:52:46 +030064 - require:
65 - file: /etc/powerdns/dbtemplate.sql
Ivan Udovichenkod2151542018-08-31 16:44:26 +030066{%- endif %}
Ivan Udovichenkoe25bced2018-08-07 12:52:46 +030067{%- if server.supermasters is defined %}
68{% for supermaster in server.supermasters %}
69use_supermaster_{{ supermaster.ip }}:
70 powerdns_mysql.row_present:
71 - table: supermasters
72 - where_sql: ip="{{ supermaster.ip }}"
73 - database: {{ server.backend.dbname }}
74 - data:
75 ip: {{ supermaster.ip }}
76 nameserver: {{ supermaster.nameserver }}
77 account: {{supermaster.account }}
78 {%- if server.overwrite_supermasters is defined %}
79 - update: {{ server.overwrite_supermasters }}
80 {%- endif %}
Oleh Hryhorovf5949792018-10-09 11:00:37 +030081 {%- if grains.get('noservices') %}
82 - onlyif: /bin/false
83 {%- endif %}
Ivan Udovichenkoe25bced2018-08-07 12:52:46 +030084 - connection_charset: {{ mysql_connection_args.connection_charset }}
85{%- if mysql_connection_args.connection_default_file %}
86 - connection_default_file: {{ mysql_connection_args.connection_default_file }}
87{%- endif %}
88{%- if mysql_connection_args.use_socket == True %}
89 - connection_unix_socket: {{ mysql_connection_args.connection_unix_socket }}
90{%- else %}
91 - connection_host: {{ mysql_connection_args.connection_host }}
92 - connection_port: {{ mysql_connection_args.connection_port }}
93{%- endif %}
94 - connection_user: {{ mysql_connection_args.connection_user }}
95 - connection_pass: {{ mysql_connection_args.connection_pass }}
96{%- if not powerdns_db_tables %}
97 - require:
98 - powerdns_init_mysql_db
99{%- endif %}
100 - watch_in:
101 - service: powerdns_service
102{% endfor %}
103{%- endif %}
Ivan Suzdal67bcad52017-05-26 18:45:54 +0300104/etc/powerdns/pdns.d/pdns.local.gmysql.conf:
105 file.managed:
106 - source: salt://powerdns/files/backends/mysql.conf
107 - template: jinja
108 - user: root
109 - group: root
110 - mode: 640
111 - require:
112 - pkg: powerdns_mysql_packages
113 - watch_in:
114 - service: powerdns_service