From 2f2cd972ac9db7704ca5a28ece521842a7e6fdf0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Hertzog?= Date: Tue, 23 Dec 2014 17:35:26 +0100 Subject: [PATCH 1/2] Use items() method to loop over nodegroups/log_granular_levels dictionaries MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Otherwise you get an “ValueError: too many values to unpack” exception when you make use of those entries in your pillar data. --- salt/files/master.d/_defaults.conf | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/salt/files/master.d/_defaults.conf b/salt/files/master.d/_defaults.conf index 9d363bb..84e0509 100644 --- a/salt/files/master.d/_defaults.conf +++ b/salt/files/master.d/_defaults.conf @@ -869,12 +869,12 @@ peer_run: # {% if 'log_granular_levels' in master %} log_granular_levels: - {% for name, lvl in master['log_granular_levels'] %} + {% for name, lvl in master['log_granular_levels'].items() %} {{ name }}: {{ lvl }} {% endfor %} {% elif 'log_granular_levels' in salt %} log_granular_levels: - {% for name, lvl in salt['log_granular_levels'] %} + {% for name, lvl in salt['log_granular_levels'].items() %} {{ name }}: {{ lvl }} {% endfor %} {% else %} @@ -891,12 +891,12 @@ log_granular_levels: # group2: 'G@os:Debian and foo.domain.com' {% if 'nodegroups' in master %} nodegroups: - {% for name, lvl in master['nodegroups'] %} + {% for name, lvl in master['nodegroups'].items() %} {{ name }}: {{ lvl }} {% endfor %} {% elif 'nodegroups' in salt %} nodegroups: - {% for name, lvl in salt['nodegroups'] %} + {% for name, lvl in salt['nodegroups'].items() %} {{ name }}: {{ lvl }} {% endfor %} {% endif %} From 8a828b506e08f0f5098b9084378a4f9881586cf7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Hertzog?= Date: Tue, 23 Dec 2014 17:38:50 +0100 Subject: [PATCH 2/2] Use items() method instead of iteritems() for Python 3 compatibility In Python 3, dict.items() is already an iterator while dict.iteritems() no longer exits. In Python 2, dict.items() is not an iterator but it works and the small performance hit doesn't really matter for the salt config pillar data which is really small. --- salt/files/master.d/_defaults.conf | 8 ++++---- salt/files/minion.d/_defaults.conf | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/salt/files/master.d/_defaults.conf b/salt/files/master.d/_defaults.conf index 84e0509..cca2407 100644 --- a/salt/files/master.d/_defaults.conf +++ b/salt/files/master.d/_defaults.conf @@ -613,10 +613,10 @@ fileserver_backend: gitfs_remotes: {%- for remote in master['gitfs_remotes'] %} {%- if remote is iterable and remote is not string %} - {%- for repo, children in remote.iteritems() %} + {%- for repo, children in remote.items() %} - {{ repo }}: {%- for child in children %} - {%- for key, value in child.iteritems() %} + {%- for key, value in child.items() %} - {{ key }}: {{ value }} {%- endfor -%} {%- endfor -%} @@ -942,7 +942,7 @@ win_gitrepos: ##### Halite ##### ########################################## halite: - {% for name, value in master['halite'].iteritems() %} + {% for name, value in master['halite'].items() %} {{ name }}: {{ value }} {% endfor %} {% endif %} @@ -951,7 +951,7 @@ halite: ##### rest_cherrypy ##### ########################################## rest_cherrypy: - {% for name, value in master['rest_cherrypy'].iteritems() %} + {% for name, value in master['rest_cherrypy'].items() %} {{ name }}: {{ value }} {% endfor %} {% endif %} diff --git a/salt/files/minion.d/_defaults.conf b/salt/files/minion.d/_defaults.conf index 95be519..875e1e0 100644 --- a/salt/files/minion.d/_defaults.conf +++ b/salt/files/minion.d/_defaults.conf @@ -458,10 +458,10 @@ file_roots: gitfs_remotes: {%- for remote in minion['gitfs_remotes'] %} {%- if remote is iterable and remote is not string %} - {%- for repo, children in remote.iteritems() %} + {%- for repo, children in remote.items() %} - {{ repo }}: {%- for child in children %} - {%- for key, value in child.iteritems() %} + {%- for key, value in child.items() %} - {{ key }}: {{ value }} {%- endfor -%} {%- endfor -%}