Skip to content
Snippets Groups Projects
Commit 524b6e98 authored by Matthew X. Economou's avatar Matthew X. Economou
Browse files

Allow changing connection_user by setting the 'mysql:server:root_user' Pillar key

In some MySQL server configurations (e.g., Amazon RDS), the root account
may not be available.  Instead, one may need to use a different account
in order to perform database administration.  This change replaced hard-
coded references to the root account with a Pillar lookup that defaults
to 'root'.  Existing users of this formula should see no change in its
behavior.
parent fb770bc1
No related branches found
No related tags found
No related merge requests found
{% from "mysql/defaults.yaml" import rawmap with context %} {% from "mysql/defaults.yaml" import rawmap with context %}
{%- set mysql = salt['grains.filter_by'](rawmap, grain='os', merge=salt['pillar.get']('mysql:lookup')) %} {%- set mysql = salt['grains.filter_by'](rawmap, grain='os', merge=salt['pillar.get']('mysql:lookup')) %}
{% set mysql_root_user = salt['pillar.get']('mysql:server:root_user', 'root') %}
{% set mysql_root_pass = salt['pillar.get']('mysql:server:root_password', salt['grains.get']('server_id')) %} {% set mysql_root_pass = salt['pillar.get']('mysql:server:root_password', salt['grains.get']('server_id')) %}
{% set mysql_host = salt['pillar.get']('mysql:server:host', 'localhost') %} {% set mysql_host = salt['pillar.get']('mysql:server:host', 'localhost') %}
{% set db_states = [] %} {% set db_states = [] %}
...@@ -14,7 +15,7 @@ include: ...@@ -14,7 +15,7 @@ include:
mysql_database.present: mysql_database.present:
- name: {{ database }} - name: {{ database }}
- connection_host: '{{ mysql_host }}' - connection_host: '{{ mysql_host }}'
- connection_user: root - connection_user: '{{ mysql_root_user }}'
{% if mysql_root_pass %} {% if mysql_root_pass %}
- connection_pass: '{{ mysql_root_pass }}' - connection_pass: '{{ mysql_root_pass }}'
{% endif %} {% endif %}
......
{% set mysql_root_user = salt['pillar.get']('mysql:server:root_user', 'root') %}
{% set mysql_root_pass = salt['pillar.get']('mysql:server:root_password', salt['grains.get']('server_id')) %} {% set mysql_root_pass = salt['pillar.get']('mysql:server:root_password', salt['grains.get']('server_id')) %}
{% set mysql_host = salt['pillar.get']('mysql:server:host', 'localhost') %} {% set mysql_host = salt['pillar.get']('mysql:server:host', 'localhost') %}
...@@ -8,7 +9,7 @@ mysql remove test database: ...@@ -8,7 +9,7 @@ mysql remove test database:
mysql_database.absent: mysql_database.absent:
- name: test - name: test
- host: '{{ mysql_host }}' - host: '{{ mysql_host }}'
- connection_user: root - connection_user: '{{ mysql_root_user }}'
{% if mysql_root_pass %} {% if mysql_root_pass %}
- connection_pass: '{{ mysql_root_pass }}' - connection_pass: '{{ mysql_root_pass }}'
{% endif %} {% endif %}
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
{% set os = salt['grains.get']('os', None) %} {% set os = salt['grains.get']('os', None) %}
{% set os_family = salt['grains.get']('os_family', None) %} {% set os_family = salt['grains.get']('os_family', None) %}
{% set mysql_root_user = salt['pillar.get']('mysql:server:root_user', 'root') %}
{% set mysql_root_password = salt['pillar.get']('mysql:server:root_password', salt['grains.get']('server_id')) %} {% set mysql_root_password = salt['pillar.get']('mysql:server:root_password', salt['grains.get']('server_id')) %}
{% set mysql_host = salt['pillar.get']('mysql:server:host', 'localhost') %} {% set mysql_host = salt['pillar.get']('mysql:server:host', 'localhost') %}
...@@ -41,8 +42,10 @@ mysql_delete_anonymous_user_{{ host }}: ...@@ -41,8 +42,10 @@ mysql_delete_anonymous_user_{{ host }}:
- host: {{ host or "''" }} - host: {{ host or "''" }}
- name: '' - name: ''
- connection_host: '{{ mysql_host }}' - connection_host: '{{ mysql_host }}'
- connection_user: root - connection_user: '{{ mysql_root_user }}'
- connection_pass: {{ mysql_root_password }} {% if mysql_root_password %}
- connection_pass: '{{ mysql_root_password }}'
{% endif %}
- connection_charset: utf8 - connection_charset: utf8
- require: - require:
- service: mysqld - service: mysqld
......
{% from "mysql/defaults.yaml" import rawmap with context %} {% from "mysql/defaults.yaml" import rawmap with context %}
{%- set mysql = salt['grains.filter_by'](rawmap, grain='os', merge=salt['pillar.get']('mysql:server:lookup')) %} {%- set mysql = salt['grains.filter_by'](rawmap, grain='os', merge=salt['pillar.get']('mysql:server:lookup')) %}
{%- set mysql_root_user = salt['pillar.get']('mysql:server:root_user', 'root') %}
{%- set mysql_root_pass = salt['pillar.get']('mysql:server:root_password', 'somepass') %} {%- set mysql_root_pass = salt['pillar.get']('mysql:server:root_password', 'somepass') %}
{%- set mysql_host = salt['pillar.get']('mysql:server:host', 'localhost') %} {%- set mysql_host = salt['pillar.get']('mysql:server:host', 'localhost') %}
...@@ -33,7 +34,7 @@ include: ...@@ -33,7 +34,7 @@ include:
- allow_passwordless: True - allow_passwordless: True
{%- endif %} {%- endif %}
- connection_host: '{{ mysql_host }}' - connection_host: '{{ mysql_host }}'
- connection_user: root - connection_user: '{{ mysql_root_user }}'
{% if mysql_root_pass %} {% if mysql_root_pass %}
- connection_pass: '{{ mysql_root_pass }}' - connection_pass: '{{ mysql_root_pass }}'
{% endif %} {% endif %}
...@@ -49,7 +50,7 @@ include: ...@@ -49,7 +50,7 @@ include:
- user: {{ name }} - user: {{ name }}
- host: '{{ host }}' - host: '{{ host }}'
- connection_host: '{{ mysql_host }}' - connection_host: '{{ mysql_host }}'
- connection_user: root - connection_user: '{{ mysql_root_user }}'
{% if mysql_root_pass -%} {% if mysql_root_pass -%}
- connection_pass: '{{ mysql_root_pass }}' - connection_pass: '{{ mysql_root_pass }}'
{% endif %} {% endif %}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment