Permalink
Browse files

Fix iteritems() usage when no pillar are defined

As a side effect, simplify Jinja templates.
  • Loading branch information...
tmartinfr committed Feb 18, 2014
1 parent 31944fa commit 2ae2be67592df153fc2b4841d2c38c5aafbf574f
@@ -10,8 +10,7 @@ sshusers:
group.present:
- system: True

{% if pillar['users'] is defined %}
{% for user, userinfo in pillar['users'].iteritems() %}
{% for user, userinfo in salt['pillar.get']('users', {}).iteritems() %}
{{ user }}:
group.present:
- gid: {{ userinfo['uid'] }}
@@ -60,7 +59,6 @@ sshusers:
- require:
- user: {{ user }}
{% endfor %}
{% endif %}


##############################################################################
@@ -53,7 +53,7 @@ mysql-clean:
# Read pillar databases:mysql:users then create users and databases
##############################################################################

{% for user, password in salt['pillar.get']('databases:mysql:users').iteritems() %}
{% for user, password in salt['pillar.get']('databases:mysql:users', {}).iteritems() %}
mysql-user-{{ user }}:
mysql_user:
- present
@@ -35,7 +35,7 @@ postgresql:
# Read pillar databases:postgresql:users then create users and databases
##############################################################################

{% for user, password in salt['pillar.get']('databases:postgresql:users').iteritems() %}
{% for user, password in salt['pillar.get']('databases:postgresql:users', {}).iteritems() %}
postgresql-user-{{ user }}:
postgres_user:
- present
@@ -36,8 +36,7 @@ awstats:
- pkg: awstats

# For each user in pillar http:users
{% if salt['pillar.get']('http:users') is defined %}
{% for user, userinfo in salt['pillar.get']('http:users').iteritems() %}
{% for user, userinfo in salt['pillar.get']('http:users', {}).iteritems() %}
{% if userinfo['root_paths'] is defined %}

# Awstats root for each user
@@ -50,7 +49,7 @@ awstats:
- user: {{ user }}
- file: {{ salt['pillar.get']('http:basedir') }}/{{ user }}

{% for root_path, root_pathinfo in userinfo['root_paths'].iteritems() %}
{% for root_path, root_pathinfo in userinfo.get('root_paths', {}).iteritems() %}

# Awstats config file for each user
/etc/awstats/awstats.{{ user }}-{{ root_path }}.conf:
@@ -84,5 +83,4 @@ awstats:
{% endfor %}
{% endif %}
{% endfor %}
{% endif %}

@@ -58,10 +58,8 @@ apache2-utils:
# Read http:users pillar and create virtual hosts
##############################################################################

{% if salt['pillar.get']('http:users') is defined %}
{% for user, userinfo in salt['pillar.get']('http:users').iteritems() %}
{% if userinfo['root_paths'] is defined %}
{% for root_path, root_pathinfo in userinfo['root_paths'].iteritems() %}
{% for user, userinfo in salt['pillar.get']('http:users', {}).iteritems() %}
{% for root_path, root_pathinfo in userinfo.get('root_paths', {}).iteritems() %}

/etc/nginx/sites-available/{{ user }}-{{ root_path }}:
file.managed:
@@ -93,7 +91,5 @@ apache2-utils:
- service: nginx

{% endfor %}
{% endif %}
{% endfor %}
{% endif %}

@@ -14,8 +14,7 @@
- mode: 711

# For each user in pillar http:users
{% if salt['pillar.get']('http:users') is defined %}
{% for user, userinfo in salt['pillar.get']('http:users').iteritems() %}
{% for user, userinfo in salt['pillar.get']('http:users', {}).iteritems() %}

# Web user and group
{{ user }}:
@@ -135,21 +134,20 @@
{% endfor %}
{% endif %}
{% endfor %}
{% endif %}

# Add www-data system user in each user group, so it can access static files
www-data:
user.present:
- groups:
- www-data
{% if salt['pillar.get']('http:users') is defined %}
{% for user, userinfo in salt['pillar.get']('http:users').iteritems() %}
{% if salt['pillar.get']('http:users') %}
{% for user, userinfo in salt['pillar.get']('http:users', {}).iteritems() %}
{% if userinfo['root_paths'] is defined %}
- {{ user }}
{% endif %}
{% endfor %}
- require:
{% for user, userinfo in salt['pillar.get']('http:users').iteritems() %}
{% for user, userinfo in salt['pillar.get']('http:users', {}).iteritems() %}
{% if userinfo['root_paths'] is defined %}
- group: {{ user }}
{% endif %}
@@ -32,12 +32,9 @@ php5-fpm:
/etc/php5/fpm/pool.d/www.conf:
file.absent

{% if salt['pillar.get']('http:users') is defined %}
{% for user, userinfo in salt['pillar.get']('http:users').iteritems() %}
{% if userinfo['root_paths'] is defined %}
{% for root_path, root_pathinfo in userinfo['root_paths'].iteritems() %}
{% if root_pathinfo['config_tags'] is defined %}
{% if 'php5' in root_pathinfo['config_tags'] %}
{% for user, userinfo in salt['pillar.get']('http:users', {}).iteritems() %}
{% for root_path, root_pathinfo in userinfo.get('root_paths', {}).iteritems() %}
{% if 'php5' in root_pathinfo.get('config_tags', {}) %}
/etc/php5/fpm/pool.d/{{ user }}-{{ root_path }}.conf:
file.managed:
- user: root
@@ -54,9 +51,6 @@ php5-fpm:
- watch_in:
- service: php5-fpm
{% endif %}
{% endif %}
{% endfor %}
{% endif %}
{% endfor %}
{% endif %}

@@ -16,7 +16,7 @@ include:
- group: root
- makedirs: True

{% for git_project, git_projectinfo in pillar['git_projects'].iteritems() %}
{% for git_project, git_projectinfo in salt['pillar.get']('git_projects', {}).iteritems() %}
{{ git_project }}:
group.present:
- gid: {{ git_projectinfo['uid'] }}

0 comments on commit 2ae2be6

Please sign in to comment.