|
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- {%- if pillar.get('mysql', {}).server is defined %}
-
- {%- set server = pillar.mysql.server %}
-
- {%- for database_name, database in server.get('database', {}).iteritems() %}
-
- mysql_database_{{ database_name }}:
- mysql_database.present:
- - name: {{ database_name }}
-
- {%- for user in database.users %}
-
- mysql_user_{{ user.name }}_{{ database_name }}_{{ user.host }}:
- mysql_user.present:
- - host: '{{ user.host }}'
- - name: '{{ user.name }}'
- - password: {{ user.password }}
-
- mysql_grants_{{ user.name }}_{{ database_name }}_{{ user.host }}:
- mysql_grants.present:
- - grant: {{ user.rights }}
- - database: '{{ database_name }}.*'
- - user: '{{ user.name }}'
- - host: '{{ user.host }}'
- - require:
- - mysql_user: mysql_user_{{ user.name }}_{{ database_name }}_{{ user.host }}
- - mysql_database: mysql_database_{{ database_name }}
-
- {%- endfor %}
-
- {%- if database.initial_data is defined %}
-
- /root/mysql/scripts/restore_{{ database_name }}.sh:
- file.managed:
- - source: salt://mysql/conf/restore.sh
- - mode: 770
- - template: jinja
- - defaults:
- database_name: {{ database_name }}
- database: {{ database }}
- - require:
- - file: mysql_dirs
- - mysql_database: mysql_database_{{ database_name }}
-
- restore_mysql_database_{{ database_name }}:
- cmd.run:
- - name: /root/mysql/scripts/restore_{{ database_name }}.sh
- - unless: "[ -f /root/mysql/flags/{{ database_name }}-installed ]"
- - cwd: /root
- - require:
- - file: /root/mysql/scripts/restore_{{ database_name }}.sh
-
- {%- endif %}
-
- {%- endfor %}
-
- {%- for user in server.get('users', []) %}
-
- mysql_user_{{ user.name }}_{{ user.host }}:
- mysql_user.present:
- - host: '{{ user.host }}'
- - name: '{{ user.name }}'
- {%- if user.password is defined %}
- - password: {{ user.password }}
- {%- else %}
- - allow_passwordless: True
- {%- endif %}
-
- {%- endfor %}
-
- {%- endif %}
|