Skip to content
Snippets Groups Projects
Unverified Commit 52ed6ab6 authored by alxwr's avatar alxwr Committed by GitHub
Browse files

Merge pull request #217 from alxwr/remove-db-or-user

Remove DB and/or user
parents 49e4a819 39915a49
No related branches found
No related tags found
No related merge requests found
...@@ -13,19 +13,31 @@ include: ...@@ -13,19 +13,31 @@ include:
{% for database_obj in salt['pillar.get']('mysql:database', []) %} {% for database_obj in salt['pillar.get']('mysql:database', []) %}
{% set state_id = 'mysql_db_' ~ loop.index0 %} {% set state_id = 'mysql_db_' ~ loop.index0 %}
{% set database = database_obj.get('name') if database_obj is mapping else database_obj %} {% if not database_obj %}{# in case database_obj == [] #}
{% continue %}
{% elif database_obj is mapping %}
{% set database = database_obj.get('name') %}
{% set present = database_obj.get('present', True) %}
{% else %}
{% set database = database_obj %}
{% set present = True %}
{% endif %}
{{ state_id }}: {{ state_id }}:
{%- if present %}
mysql_database.present: mysql_database.present:
{% if database_obj is mapping %}
- character_set: {{ database_obj.get('character_set', '') }}
- collate: {{ database_obj.get('collate', '') }}
{% endif %}
{% else %}
mysql_database.absent:
{% endif %}
- name: {{ database }} - name: {{ database }}
- connection_host: '{{ mysql_host }}' - connection_host: '{{ mysql_host }}'
- connection_user: '{{ mysql_salt_user }}' - connection_user: '{{ mysql_salt_user }}'
{% if mysql_salt_pass %} {% if mysql_salt_pass %}
- connection_pass: '{{ mysql_salt_pass }}' - connection_pass: '{{ mysql_salt_pass }}'
{% endif %} {% endif %}
{% if database_obj is mapping %}
- character_set: {{ database_obj.get('character_set', '') }}
- collate: {{ database_obj.get('collate', '') }}
{% endif %}
- connection_charset: utf8 - connection_charset: utf8
{% if salt['pillar.get'](['mysql', 'schema', database, 'load']|join(':'), False) %} {% if salt['pillar.get'](['mysql', 'schema', database, 'load']|join(':'), False) %}
......
...@@ -34,6 +34,7 @@ include: ...@@ -34,6 +34,7 @@ include:
{% set state_id = 'mysql_user_' ~ name ~ '_' ~ host%} {% set state_id = 'mysql_user_' ~ name ~ '_' ~ host%}
{{ state_id }}: {{ state_id }}:
{%- if user.get('present', True) %}
mysql_user.present: mysql_user.present:
- name: {{ name }} - name: {{ name }}
- host: '{{ host }}' - host: '{{ host }}'
...@@ -43,12 +44,17 @@ include: ...@@ -43,12 +44,17 @@ include:
- password: '{{ user['password'] }}' - password: '{{ user['password'] }}'
{%- else %} {%- else %}
- allow_passwordless: True - allow_passwordless: True
{%- endif %}
{%- else %}
mysql_user.absent:
- name: {{ name }}
- host: '{{ host }}'
{%- endif %} {%- endif %}
- connection_host: '{{ mysql_host }}' - connection_host: '{{ mysql_host }}'
- connection_user: '{{ mysql_salt_user }}' - connection_user: '{{ mysql_salt_user }}'
{% if mysql_salt_pass %} {%- if mysql_salt_pass %}
- connection_pass: '{{ mysql_salt_pass }}' - connection_pass: '{{ mysql_salt_pass }}'
{% endif %} {%- endif %}
- connection_charset: utf8 - connection_charset: utf8
{%- if 'grants' in user %} {%- if 'grants' in user %}
......
...@@ -72,6 +72,9 @@ mysql: ...@@ -72,6 +72,9 @@ mysql:
- name: bar - name: bar
character_set: utf8 character_set: utf8
collate: utf8_general_ci collate: utf8_general_ci
# Delete DB
- name: obsolete_db
present: False
schema: schema:
foo: foo:
load: True load: True
...@@ -143,6 +146,12 @@ mysql: ...@@ -143,6 +146,12 @@ mysql:
- database: foo - database: foo
grants: ['select', 'insert', 'update'] grants: ['select', 'insert', 'update']
# Remove a user
obsoleteuser:
host: localhost
# defaults to True
present: False
# Override any names defined in map.jinja # Override any names defined in map.jinja
# serverpkg: mysql-server # serverpkg: mysql-server
# clientpkg: mysql-client # clientpkg: mysql-client
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment