Hi, I am trying to write states that deal with creating databases, mysql user & grants. My pillar stack looks like this:
I envision the states looking somewhat like below, where a loop is started through each database, and a subloop started which cycles through users & their respective grants. This is one way I'd do it with a bash script, but think I might be missing some jinja magic.
{% for db, args in pillar['multisite_mysql_dbs'].iteritems %}
mysql db {{ db }}:
mysql_database.present:
- name: {{ db }}
{% for user in args['users'] %}
mysql user {{ users }}:
mysql_user.present:
- name: {{ user }}
- host: localhost
- password_hash: {{ args['password'] }}
- require:
- file: /etc/salt/minion.d/mysql.conf
mysql grants for {{ user }}:
mysql_grants.present:
- user: {{ user }}
- grant: {{ args['grants'] }}
- database: {{ db }}
- require:
- mysql_user: {{ user }}
- file: /etc/salt/minion.d/mysql.conf
{% endfor %}
{% endfor %}
local:
Data failed to compile:
----------
Rendering SLS environments.all.db.mysql failed, render error: Traceback (most recent call last):
File "/usr/lib/python2.6/dist-packages/salt/utils/templates.py", line 63, in render_tmpl
output = render_str(tmplstr, context, tmplpath)
File "/usr/lib/python2.6/dist-packages/salt/utils/templates.py", line 116, in render_jinja_tmpl
output = jinja_env.from_string(tmplstr).render(**context)
File "/usr/lib/pymodules/python2.6/jinja2/environment.py", line 891, in render
return self.environment.handle_exception(exc_info, True)
File "<template>", line 82, in top-level template code
TypeError: 'builtin_function_or_method' object is not iterable
Traceback (most recent call last):
File "/usr/lib/python2.6/dist-packages/salt/state.py", line 1877, in render_state
rendered_sls=mods
File "/usr/lib/python2.6/dist-packages/salt/template.py", line 68, in compile_template
ret = render(input_data, env, sls, **render_kwargs)
File "/usr/lib/python2.6/dist-packages/salt/renderers/jinja.py", line 41, in render
tmp_data.get('data', 'Unknown render error in jinja renderer')
SaltRenderError: Traceback (most recent call last):
File "/usr/lib/python2.6/dist-packages/salt/utils/templates.py", line 63, in render_tmpl
output = render_str(tmplstr, context, tmplpath)
File "/usr/lib/python2.6/dist-packages/salt/utils/templates.py", line 116, in render_jinja_tmpl
output = jinja_env.from_string(tmplstr).render(**context)
File "/usr/lib/pymodules/python2.6/jinja2/environment.py", line 891, in render
return self.environment.handle_exception(exc_info, True)
File "<template>", line 82, in top-level template code
TypeError: 'builtin_function_or_method' object is not iterable