From 5d5c4bc91a28eadcf525206d5a8a73c3c7bef39e Mon Sep 17 00:00:00 2001 From: Rene Mewissen Date: Thu, 25 Jul 2024 11:08:14 +0200 Subject: [PATCH] import data only if database did not exist before; generate password, if not set in vars --- roles/nameserver/tasks/install_powerdns_server.yml | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/roles/nameserver/tasks/install_powerdns_server.yml b/roles/nameserver/tasks/install_powerdns_server.yml index 5ff5ec1..631123d 100644 --- a/roles/nameserver/tasks/install_powerdns_server.yml +++ b/roles/nameserver/tasks/install_powerdns_server.yml @@ -23,6 +23,7 @@ encoding: "utf8" # not required. Encoding mode to use, examples include C(utf8) or C(latin1_swedish_ci) config_file: "/etc/mysql/my.cnf" # not required. Specify a config file from which user and password are to be read. login_unix_socket: "{{ pdns_mysql_socket }}" # not required. The path to a Unix domain socket for local connections. + register: database_exists - name: nameserver | powerdns-server | import database mysql_db: name: "{{ pdns_db_name }}" @@ -30,10 +31,11 @@ target: "{{ pdns_mysql_schema }}" # not required. Location, on the remote host, of the dump file to read from or write to. Uncompressed SQL files (C(.sql)) as well as bzip2 (C(.bz2)), gzip (C(.gz)) and xz (Added in 2.0) compressed files are supported. config_file: "/etc/mysql/my.cnf" # not required. Specify a config file from which user and password are to be read. login_unix_socket: "{{ pdns_mysql_socket }}" # not required. The path to a Unix domain socket for local connections. + when: database_exists.changed - name: nameserver | powerdns-server | create database user mysql_user: name: "{{ pdns_db_user }}" # required. Name of the user (role) to add or remove. - password: "{{ pdns_db_passwd }}" # not required. Set the user's password.. + password: "{{ pdns_db_passwd | default(lookup('password', '/etc/powerdns/pdns.d/.mysqlpw' length=20)) }}" # not required. Set the user's password.. host: localhost priv: "{{ pdns_db_name }}.*:ALL" # not required. MySQL privileges string in the format: C(db.table:priv1,priv2). Multiple privileges can be specified by separating each one using a forward slash: C(db.table:priv/db.table:priv). The format is based on MySQL C(GRANT) statement. Database and table names can be quoted, MySQL-style. If column privileges are used, the C(priv1,priv2) part must be exactly as returned by a C(SHOW GRANT) statement. If not followed, the module will always report changes. It includes grouping columns by permission (C(SELECT(col1,col2)) instead of C(SELECT(col1),SELECT(col2))). append_privs: False # not required. Append the privileges defined by priv to the existing ones for this user instead of overwriting existing ones. @@ -49,6 +51,7 @@ mode: "0644" owner: "root" group: "root" + force: no when: - powerdns_primary is defined - powerdns_primary is true @@ -57,10 +60,12 @@ service: name: "named" state: stopped - enabled: False + enabled: false + rescue: + - set_fact: task_failed=true - name: nameserver | powerdns-recursor | enable service service: name: "pdns" state: started - enabled: True + enabled: true