Ivan Suzdal | 67bcad5 | 2017-05-26 18:45:54 +0300 | [diff] [blame] | 1 | {%- from "powerdns/map.jinja" import server with context %} |
| 2 | {%- from "powerdns/server/packages.jinja" import packages with context %} |
| 3 | include: |
| 4 | - powerdns.server.service |
| 5 | |
Ivan Udovichenko | e25bced | 2018-08-07 12:52:46 +0300 | [diff] [blame] | 6 | {%- 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 Suzdal | 67bcad5 | 2017-05-26 18:45:54 +0300 | [diff] [blame] | 29 | powerdns_mysql_packages: |
| 30 | pkg.installed: |
| 31 | - names: {{ packages.backends.mysql }} |
| 32 | |
Ivan Udovichenko | e25bced | 2018-08-07 12:52:46 +0300 | [diff] [blame] | 33 | /etc/powerdns/dbtemplate.sql: |
| 34 | file.managed: |
| 35 | - source: salt://powerdns/files/mysql.sql |
| 36 | - require: |
| 37 | - pkg: powerdns_mysql_packages |
| 38 | |
Oleh Hryhorov | f594979 | 2018-10-09 11:00:37 +0300 | [diff] [blame^] | 39 | {%- set powerdns_db_tables = False %} |
| 40 | |
| 41 | {%- if grains.get('noservices') is not defined %} |
Ivan Udovichenko | e25bced | 2018-08-07 12:52:46 +0300 | [diff] [blame] | 42 | {%- set powerdns_db_tables = salt['mysql.db_tables'](server.backend.dbname, **mysql_connection_args) %} |
Oleh Hryhorov | f594979 | 2018-10-09 11:00:37 +0300 | [diff] [blame^] | 43 | {%- endif %} |
Ivan Udovichenko | e25bced | 2018-08-07 12:52:46 +0300 | [diff] [blame] | 44 | {%- if not powerdns_db_tables %} |
| 45 | powerdns_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 Hryhorov | f594979 | 2018-10-09 11:00:37 +0300 | [diff] [blame^] | 50 | {%- if grains.get('noservices') %} |
| 51 | - onlyif: /bin/false |
| 52 | {%- endif %} |
Ivan Udovichenko | e25bced | 2018-08-07 12:52:46 +0300 | [diff] [blame] | 53 | {%- 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 Udovichenko | e25bced | 2018-08-07 12:52:46 +0300 | [diff] [blame] | 64 | - require: |
| 65 | - file: /etc/powerdns/dbtemplate.sql |
Ivan Udovichenko | d215154 | 2018-08-31 16:44:26 +0300 | [diff] [blame] | 66 | {%- endif %} |
Ivan Udovichenko | e25bced | 2018-08-07 12:52:46 +0300 | [diff] [blame] | 67 | {%- if server.supermasters is defined %} |
| 68 | {% for supermaster in server.supermasters %} |
| 69 | use_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 Hryhorov | f594979 | 2018-10-09 11:00:37 +0300 | [diff] [blame^] | 81 | {%- if grains.get('noservices') %} |
| 82 | - onlyif: /bin/false |
| 83 | {%- endif %} |
Ivan Udovichenko | e25bced | 2018-08-07 12:52:46 +0300 | [diff] [blame] | 84 | - 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 Suzdal | 67bcad5 | 2017-05-26 18:45:54 +0300 | [diff] [blame] | 104 | /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 |