From 4ff1a746d6c18c8e79ada0e9f5f4f3c0553970a6 Mon Sep 17 00:00:00 2001
From: genus <genus.alexey@gmail.com>
Date: Wed, 29 Jul 2015 19:48:56 +0300
Subject: [PATCH 01/16] Add master_type option

---
 salt/files/minion.d/f_defaults.conf | 1 +
 1 file changed, 1 insertion(+)

diff --git a/salt/files/minion.d/f_defaults.conf b/salt/files/minion.d/f_defaults.conf
index 7bdf59b..681fa96 100644
--- a/salt/files/minion.d/f_defaults.conf
+++ b/salt/files/minion.d/f_defaults.conf
@@ -157,6 +157,7 @@ mine_functions:
 
 # verify_master_pubkey_sign
 {{ get_config('verify_master_pubkey_sign', 'False') }}
+{{ get_config('master_type', 'str') }}
 
 # include extra config
 {% if 'include' in cfg_minion -%}

From c014015e79ed48862873a2f496a2ed5cbd49cc37 Mon Sep 17 00:00:00 2001
From: "Matthew X. Economou" <xenophon@irtnog.org>
Date: Sun, 2 Aug 2015 21:17:36 -0400
Subject: [PATCH 02/16] Configure the salt-api service to start at boot time

---
 salt/api.sls | 1 +
 1 file changed, 1 insertion(+)

diff --git a/salt/api.sls b/salt/api.sls
index 812f243..a10081f 100644
--- a/salt/api.sls
+++ b/salt/api.sls
@@ -9,6 +9,7 @@ salt-api:
     - name: {{ salt_settings.salt_api }}
 {% endif %}
   service.running:
+    - enable: True
     - name: {{ salt_settings.api_service }}
     - require:
       - service: {{ salt_settings.master_service }}

From 825fd7cd77ab34fcf750af580d7c040a8b2ff734 Mon Sep 17 00:00:00 2001
From: jpic <jamespic@gmail.com>
Date: Thu, 6 Aug 2015 11:35:20 +0200
Subject: [PATCH 03/16] Fixed pillar_roots generation for salt-master.

With a simple pillar like this::

    $ sudo salt-call --config-dir /srv/etc/bootstrap --pillar-root /srv/pillar pillar.get salt:pillar_roots
    local:
        ----------
        base:
            - /srv/pillar

This was generated in /etc/salt/master.d/f_defaults.conf::

    # highstate format, and is generally just key/value pairs.
    pillar_roots:base:- /srv/pillar
    #

Resulting in parse errors by salt::

    $ sudo salt '*' state.highstate
    [ERROR   ] Error parsing configuration file: /etc/salt/master.d/f_defaults.conf - while scanning a simple key
      in "<string>", line 531, column 1:
        pillar_roots:base:- /srv/pillar
        ^
    could not found expected ':'
      in "<string>", line 532, column 1:
        #
        ^
    [ERROR   ] Error parsing configuration file: /etc/salt/master.d/f_defaults.conf - while scanning a simple key
      in "<string>", line 531, column 1:
        pillar_roots:base:- /srv/pillar
        ^
    could not found expected ':'
      in "<string>", line 532, column 1:
        #
        ^

This patch will fix it as such::

          ID: salt-master
    Function: file.recurse
        Name: /etc/salt/master.d
      Result: True
     Comment: Recursively updated /etc/salt/master.d
     Started: 11:37:12.946823
    Duration: 6255.296 ms
     Changes:
              ----------
              /etc/salt/master.d/f_defaults.conf:
                  ----------
                  diff:
                      ---
                      +++
                      @@ -528,7 +528,9 @@
                       # Pillar is laid out in the same fashion as the file server, with environments,
                       # a top file and sls files. However, pillar data does not need to be in the
                       # highstate format, and is generally just key/value pairs.
                      -pillar_roots:base:- /srv/pillar
                      +pillar_roots:
                      +  base:
                      +    - /srv/pillar
                       #

Resulting in::

    # highstate format, and is generally just key/value pairs.
    pillar_roots:
      base:
        - /srv/pillar
    #
---
 salt/files/master.d/f_defaults.conf | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/salt/files/master.d/f_defaults.conf b/salt/files/master.d/f_defaults.conf
index 5aaef11..209c47a 100644
--- a/salt/files/master.d/f_defaults.conf
+++ b/salt/files/master.d/f_defaults.conf
@@ -652,12 +652,12 @@ pillar_roots:
 {%- for dir in roots %}
     - {{ dir }}
 {%- endfor -%}
-{% endfor %}
-{%- elif 'pillar_roots' in cfg_salt -%}
+{%- endfor -%}
+{% elif 'pillar_roots' in cfg_salt -%}
 pillar_roots:
-{%- for name, roots in cfg_salt['pillar_roots']|dictsort -%}
+{%- for name, roots in cfg_salt['pillar_roots']|dictsort %}
   {{ name }}:
-{%- for dir in roots -%}
+{%- for dir in roots %}
     - {{ dir }}
 {%- endfor -%}
 {%- endfor -%}

From 02f7b279a1e6cb6f63c3d1649068476f866d160d Mon Sep 17 00:00:00 2001
From: Simon Lloyd <smlloyd@gmail.com>
Date: Sat, 8 Aug 2015 17:58:45 +0200
Subject: [PATCH 04/16] Only watch salt-api package if install_packages=true

Also watch salt-api pkg instead of salt-master one.
---
 salt/api.sls | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/salt/api.sls b/salt/api.sls
index 812f243..e6b387e 100644
--- a/salt/api.sls
+++ b/salt/api.sls
@@ -12,5 +12,7 @@ salt-api:
     - name: {{ salt_settings.api_service }}
     - require:
       - service: {{ salt_settings.master_service }}
+{% if salt_settings.install_packages %}
     - watch:
-      - pkg: salt-master
+      - pkg: salt-api
+{% endif %}

From addc6d5a2634b7f1f9c27f46ecc708b73aca5a51 Mon Sep 17 00:00:00 2001
From: Shane Poage <shane.poage@gmail.com>
Date: Wed, 19 Aug 2015 23:46:49 -0500
Subject: [PATCH 05/16] Added logic to properly install pygit2 on ubuntu
 systems and made the pygit2 installation more flexible in general.

---
 salt/defaults.yaml    |  7 +++++++
 salt/gitfs/pygit2.sls | 37 +++++++++++++++++++++++++------------
 salt/map.jinja        | 36 ++++++++++++++++++++----------------
 3 files changed, 52 insertions(+), 28 deletions(-)

diff --git a/salt/defaults.yaml b/salt/defaults.yaml
index 40a8e68..1e345ca 100644
--- a/salt/defaults.yaml
+++ b/salt/defaults.yaml
@@ -28,6 +28,13 @@ salt:
       install_from_source: True
     pygit2:
       install_from_source: True
+      version: 0.23.0
+      libgit2:
+        version: 0.23.0
+        install_from_source: True
+        build_parent_dir: /usr/src/
+        # hash necessary until github issue #9272 is addressed
+        download_hash: 683d1164e361e2a0a8d52652840e2340
     gitpython:
       install_from_source: False
 
diff --git a/salt/gitfs/pygit2.sls b/salt/gitfs/pygit2.sls
index dd7ec61..1a8341a 100644
--- a/salt/gitfs/pygit2.sls
+++ b/salt/gitfs/pygit2.sls
@@ -1,9 +1,16 @@
 {% from "salt/map.jinja" import salt_settings with context %}
+{% set pygit2_settings = salt_settings.gitfs.pygit2 %}
 
 git:
   pkg.installed
 
-{% if salt_settings.gitfs.pygit2.install_from_source %}
+{% if pygit2_settings.install_from_source %}
+{% set libgit2_settings = pygit2_settings.libgit2 %}
+
+{% if libgit2_settings.install_from_source %}
+{% set libgit2_src_dir = libgit2_settings.build_parent_dir + 'libgit2-' + libgit2_settings.version %}
+{% set libgit2_build_dir = libgit2_src_dir + '/_build' %}
+
 # we probably don't have a package or it's not a high enough version
 # install latest from source/pip
 pygit-deps:
@@ -17,32 +24,32 @@ pygit-deps:
 
 dl-libgit2-src:
   archive.extracted:
-    - name: /usr/src
-    - source: https://github.com/libgit2/libgit2/archive/v0.22.1.tar.gz
-    - source_hash: md5=dbf516d18e176bbb131de3efccfee533
+    - name: {{ libgit2_settings.build_parent_dir }}
+    - source: https://github.com/libgit2/libgit2/archive/v{{ libgit2_settings.version }}.tar.gz
+    - source_hash: md5={{ libgit2_settings.download_hash }}
     - archive_format: tar
     - keep: True
-    - if_missing: /usr/src/libgit2-0.22.1
+    - if_missing: /usr/src/libgit2-{{ libgit2_settings.version }}
 
-/usr/src/libgit2-0.22.1/_build:
+{{ libgit2_build_dir }}:
   file.directory
 
 configure-libgit2:
   cmd.run:
     - name: cmake ..
-    - cwd: /usr/src/libgit2-0.22.1/_build
-    - creates: /usr/src/libgit2-0.22.1/_build/Makefile
+    - cwd: {{ libgit2_build_dir }}
+    - creates: {{ libgit2_build_dir }}/Makefile
 
 build-libgit2:
   cmd.run:
     - name: make -j4
-    - cwd: /usr/src/libgit2-0.22.1/_build
-    - creates: /usr/src/libgit2-0.22.1/_build/libgit2.so
+    - cwd: {{ libgit2_build_dir }}
+    - creates: {{ libgit2_build_dir }}/libgit2.so
 
 install-libgit2:
   cmd.run:
     - name: make install
-    - cwd: /usr/src/libgit2-0.22.1/_build
+    - cwd: {{ libgit2_build_dir }}
     - creates: /usr/local/lib/libgit2.so
 
 run-ldconfig-after-lib-install:
@@ -51,9 +58,15 @@ run-ldconfig-after-lib-install:
     - onchanges:
       - cmd: install-libgit2
 
+{% else %}
+{{ salt_settings.libgit2 }}:
+  pkg.installed
+
+{% endif %}
+
 install-pygit2:
   pip.installed:
-    - name: pygit2
+    - name: pygit2 == {{ pygit2_settings.version }}
 
 {% else %}
 {{ salt_settings.pygit2 }}:
diff --git a/salt/map.jinja b/salt/map.jinja
index 6126b3e..027e9ee 100644
--- a/salt/map.jinja
+++ b/salt/map.jinja
@@ -9,22 +9,29 @@ Setup variable using grains['os_family'] based logic, only add key:values here
 that differ from whats in defaults.yaml
 ##}
 {% set os_family_map = salt['grains.filter_by']({
-    'Debian':  {},
-    'Ubuntu':  {},
-    'CentOS':  {},
-    'Amazon':  {},
-    'Fedora':  {},
+    'Debian':  {
+      'libgit2': 'libgit2-22',
+      'gitfs': {
+        'pygit2': {
+          'install_from_source': True,
+          'version': '0.22.1',
+          'libgit2': {
+            'install_from_source': False,
+          },
+        },
+      },
+    },
     'RedHat':  {
       'pygit2': 'python-pygit2',
       'gitfs': {
         'pygit2': {
-           'install_from_source': False
+           'install_from_source': False,
         },
       },
       'master': {
         'gitfs_provider': 'pygit2'
       },
-      'repotype': 'epel'
+      'repotype': 'epel',
     },
     'Suse':    {},
     'Gentoo':  {
@@ -32,7 +39,7 @@ that differ from whats in defaults.yaml
       'salt_minion': 'app-admin/salt',
       'salt_syndic': 'app-admin/salt',
       'salt_api': 'app-admin/salt',
-      'salt_cloud': 'app-admin/salt'
+      'salt_cloud': 'app-admin/salt',
     },
     'Arch':    {
       'salt_master': 'salt-zmq',
@@ -40,7 +47,7 @@ that differ from whats in defaults.yaml
       'salt_syndic':  'salt-zmq',
       'salt_cloud':  'salt-zmq',
       'salt_api': 'salt-zmq',
-      'salt_ssh':  'salt-zmq'
+      'salt_ssh':  'salt-zmq',
     },
     'FreeBSD': {
       'salt_master': 'py27-salt',
@@ -55,20 +62,17 @@ that differ from whats in defaults.yaml
       'minion_service': 'salt_minion',
       'master_service': 'salt_master',
       'api_service': 'salt_api',
-      'syndic_service': 'salt_syndic'
+      'syndic_service': 'salt_syndic',
     },
-  }
-  , grain="os_family"
-  , merge=salt['pillar.get']('salt:lookup'))
+  }, grain="os_family", merge=salt['pillar.get']('salt:lookup'))
 %}
 
 {## Merge the flavor_map to the default settings ##}
 {% do default_settings.salt.update(os_family_map) %}
-    
+
 {## Merge in salt:lookup pillar ##}
 {% set salt_settings = salt['pillar.get'](
     'salt',
     default=default_settings.salt,
-    merge=True
-  )
+    merge=True)
 %}

From 9779609bc4dcc400bf3fc6ec074252dee09f512f Mon Sep 17 00:00:00 2001
From: Brian Jackson <iggy@theiggy.com>
Date: Thu, 27 Aug 2015 17:37:53 -0500
Subject: [PATCH 06/16] Remove mapping test

This test isn't available in certain popular versions of Jinja (namely the one
installed by default in CentOS 6).
---
 salt/formulas.jinja | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/salt/formulas.jinja b/salt/formulas.jinja
index 599659f..0c0a50b 100644
--- a/salt/formulas.jinja
+++ b/salt/formulas.jinja
@@ -11,11 +11,7 @@
 {%- set value = salt['pillar.get']('salt_formulas:git_opts:{0}:{1}'.format(env, opt),
      salt['pillar.get']('salt_formulas:git_opts:default:{0}'.format(opt),
        defaults[opt])) -%}
-{%- if value is mapping -%}
 {{ value|yaml }}
-{%- else -%}
-{{ value }}
-{%- endif -%}
 {%- endmacro -%}
 
 {%- macro formulas_roots(env) -%}

From f0e691fa132e0c2ce998e8665c93809783f49836 Mon Sep 17 00:00:00 2001
From: Shane Poage <shane@poage.space>
Date: Tue, 1 Sep 2015 16:28:27 -0500
Subject: [PATCH 07/16] Fixed conflict with git-formula by allowing either
 inclusion of formula to install git dependency or specify a package name to
 install with a custom state ID.

---
 salt/defaults.yaml    |  4 ++++
 salt/gitfs/pygit2.sls | 10 ++++++++--
 salt/map.jinja        | 10 +++++++++-
 3 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/salt/defaults.yaml b/salt/defaults.yaml
index 1e345ca..1a7fa7a 100644
--- a/salt/defaults.yaml
+++ b/salt/defaults.yaml
@@ -29,6 +29,10 @@ salt:
     pygit2:
       install_from_source: True
       version: 0.23.0
+      git:
+        # if not false, should be state name
+        require_state: False
+        install_from_package: git
       libgit2:
         version: 0.23.0
         install_from_source: True
diff --git a/salt/gitfs/pygit2.sls b/salt/gitfs/pygit2.sls
index 1a8341a..9fce72b 100644
--- a/salt/gitfs/pygit2.sls
+++ b/salt/gitfs/pygit2.sls
@@ -1,8 +1,14 @@
 {% from "salt/map.jinja" import salt_settings with context %}
 {% set pygit2_settings = salt_settings.gitfs.pygit2 %}
 
-git:
-  pkg.installed
+{% if pygit2_settings.git.get('require_state', False) %}
+include:
+  - {{ pygit2_settings.git.require_state }}
+{% elif pygit2_settings.git.get('install_from_package', 'git') %}
+pygit2-git:
+  pkg.installed:
+    - name: {{ pygit2_settings.git.install_from_package }}
+{% endif %}
 
 {% if pygit2_settings.install_from_source %}
 {% set libgit2_settings = pygit2_settings.libgit2 %}
diff --git a/salt/map.jinja b/salt/map.jinja
index 027e9ee..3ee36c1 100644
--- a/salt/map.jinja
+++ b/salt/map.jinja
@@ -15,6 +15,10 @@ that differ from whats in defaults.yaml
         'pygit2': {
           'install_from_source': True,
           'version': '0.22.1',
+          'git': {
+            'require_state': False,
+            'install_from_package': 'git',
+          },
           'libgit2': {
             'install_from_source': False,
           },
@@ -25,7 +29,11 @@ that differ from whats in defaults.yaml
       'pygit2': 'python-pygit2',
       'gitfs': {
         'pygit2': {
-           'install_from_source': False,
+          'install_from_source': False,
+          'git': {
+            'require_state': False,
+            'install_from_package': 'git',
+          },
         },
       },
       'master': {

From 827ed47a259ad26853df378c8569b984cdf8df93 Mon Sep 17 00:00:00 2001
From: "Matthew X. Economou" <xenophon@irtnog.org>
Date: Thu, 3 Sep 2015 14:56:45 -0400
Subject: [PATCH 08/16] Filter all calls to formulas_git_opt through load_yaml

Jinja macros are not actually functions.  The only thing they can return
is a string.  In order to return structured data, the callee must
serialize it, and the caller must deserialize it.  This state formula
uses YAML as the intermediary, hence the occurrence of both the
`|yaml` (callee) and `|load_yaml` (caller) filters in its code.

The post-render "mapping values are not allowed here" error in
*salt/formulas.sls* or the broken rendering of
*salt/files/master.d/f_defaults.conf* happens because invocations of the
`formulas_git_opt` macro in several Jinja `set` statements do not get
deserialized, resulting in the trailing newline followed by three dot
characters (`...`), which YAML uses to signal the end of a document.
Correcting these rendering errors requires adding the necessary
deserialization code at those locations (i.e., filtering the macro call
through `|load_yaml`).
---
 salt/formulas.jinja | 3 ++-
 salt/formulas.sls   | 5 +++--
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/salt/formulas.jinja b/salt/formulas.jinja
index 0c0a50b..2a466a2 100644
--- a/salt/formulas.jinja
+++ b/salt/formulas.jinja
@@ -17,7 +17,8 @@
 {%- macro formulas_roots(env) -%}
 {%- set value = [] -%}
 {%- for dir in formulas.get(env, []) -%}
-{%- do value.append('{0}/{1}'.format(formulas_git_opt(env, 'basedir'), dir)) -%}
+{%- set basedir = formulas_git_opt(env, 'basedir')|load_yaml -%}
+{%- do value.append('{0}/{1}'.format(basedir, dir)) -%}
 {%- endfor -%}
 {{ value|yaml }}
 {%- endmacro -%}
diff --git a/salt/formulas.sls b/salt/formulas.sls
index 1a40745..5eaaff5 100644
--- a/salt/formulas.sls
+++ b/salt/formulas.sls
@@ -7,7 +7,7 @@
 {% for env, entries in salt['pillar.get']('salt_formulas:list', {}).iteritems() %}
 {% for entry in entries %}
 
-{% set basedir = formulas_git_opt(env, 'basedir') %}
+{% set basedir = formulas_git_opt(env, 'basedir')|load_yaml %}
 {% set gitdir = '{0}/{1}'.format(basedir, entry) %}
 {% set update = formulas_git_opt(env, 'update')|load_yaml %}
 
@@ -26,9 +26,10 @@
 {% if gitdir not in processed_gitdirs %}
 {% do processed_gitdirs.append(gitdir) %}
 {% set options = formulas_git_opt(env, 'options')|load_yaml %}
+{% set baseurl = formulas_git_opt(env, 'baseurl')|load_yaml %}
 {{ gitdir }}:
   git.latest:
-    - name: {{ formulas_git_opt(env, 'baseurl') }}/{{ entry }}.git
+    - name: {{ baseurl }}/{{ entry }}.git
     - target: {{ gitdir }}
     {%- for key, value in options.iteritems() %}
     - {{ key }}: {{ value }}

From 52893bc978753faaad15f11228f4bd14173858b3 Mon Sep 17 00:00:00 2001
From: Wolodja Wentland <w@babilen5.org>
Date: Tue, 13 Oct 2015 14:56:51 +0200
Subject: [PATCH 09/16] Manage show_jid in master configuration

This makes it easier for users to check the status of jobs that ran into
a timeout.
---
 salt/files/master.d/f_defaults.conf | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/salt/files/master.d/f_defaults.conf b/salt/files/master.d/f_defaults.conf
index 209c47a..5baf3a7 100644
--- a/salt/files/master.d/f_defaults.conf
+++ b/salt/files/master.d/f_defaults.conf
@@ -109,6 +109,9 @@
 # Return minions that timeout when running commands like test.ping
 {{ get_config('show_timeout', 'True') }}
 
+# Display the jid when a job is published
+{{ get_config('show_jid', 'False') }}
+
 # By default, output is colored. To disable colored output, set the color value
 # to False.
 {{ get_config('color', 'True') }}

From d7382e2d1f85d87aa965b29e253cb87e811a3267 Mon Sep 17 00:00:00 2001
From: root <florian.ermisch@fokus.fraunhofer.de>
Date: Tue, 13 Oct 2015 15:41:41 +0200
Subject: [PATCH 10/16] use salt_settings.syndic_service so state works on
 FreeBSD, too

---
 salt/syndic.sls | 1 +
 1 file changed, 1 insertion(+)

diff --git a/salt/syndic.sls b/salt/syndic.sls
index eaeb2a4..e372b2e 100644
--- a/salt/syndic.sls
+++ b/salt/syndic.sls
@@ -9,6 +9,7 @@ salt-syndic:
     - name: {{ salt_settings.salt_syndic }}
 {% endif %}
   service.running:
+    - name: {{ salt_settings.syndic_service }}
     - require:
       - service: salt-master
     - watch:

From 0216d665272d9b036b74f5f6438d9584dc58157a Mon Sep 17 00:00:00 2001
From: Wolodja Wentland <w@babilen5.org>
Date: Tue, 13 Oct 2015 16:37:14 +0200
Subject: [PATCH 11/16] Remove trailing whitespace from master config

---
 salt/files/master.d/f_defaults.conf | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/salt/files/master.d/f_defaults.conf b/salt/files/master.d/f_defaults.conf
index 209c47a..027fedb 100644
--- a/salt/files/master.d/f_defaults.conf
+++ b/salt/files/master.d/f_defaults.conf
@@ -135,7 +135,7 @@
 {{ get_config('minion_data_cache', 'True') }}
 
 # Store all returns in the given returner.
-# Setting this option requires that any returner-specific configuration also 
+# Setting this option requires that any returner-specific configuration also
 # be set. See various returners in salt/returners for details on required
 # configuration values. (See also, event_return_queue below.)
 #
@@ -199,12 +199,12 @@ event_return_blacklist:
 # the key rotation event as minions reconnect. Consider this carefully if this
 # salt master is managing a large number of minions.
 #
-# If disabled, it is recommended to handle this event by listening for the 
+# If disabled, it is recommended to handle this event by listening for the
 # 'aes_key_rotate' event with the 'key' tag and acting appropriately.
 {{ get_config('ping_on_rotate', 'False') }}
 
 # By default, the master deletes its cache of minion data when the key for that
-# minion is removed. To preserve the cache after key deletion, set 
+# minion is removed. To preserve the cache after key deletion, set
 # 'preserve_minion_cache' to True.
 #
 # WARNING: This may have security implications if compromised minions auth with
@@ -336,7 +336,7 @@ client_acl_blacklist:
 {% endif %}
 
 # Enforce client_acl & client_acl_blacklist when users have sudo
-# access to the salt command. 
+# access to the salt command.
 #
 {{ get_config('sudo_acl', 'False') }}
 
@@ -492,7 +492,7 @@ client_acl_blacklist:
 # the master server. The default is md5, but sha1, sha224, sha256, sha384
 # and sha512 are also supported.
 #
-# Prior to changing this value, the master should be stopped and all Salt 
+# Prior to changing this value, the master should be stopped and all Salt
 # caches should be cleared.
 {{ get_config('hash_type', 'md5') }}
 

From d730d4f2b853d659676fd724f9543505b0ee4c3e Mon Sep 17 00:00:00 2001
From: Devon Stewart <blast@hardchee.se>
Date: Tue, 6 Oct 2015 17:13:25 -0700
Subject: [PATCH 12/16] Using cfg_salt['master'] is never the right answer

- When it's iterable, the minion could be running on the master
- When it's a string, there's no advantage over just specifying
  `salt:minion:master`
---
 salt/files/minion.d/f_defaults.conf | 13 +------------
 1 file changed, 1 insertion(+), 12 deletions(-)

diff --git a/salt/files/minion.d/f_defaults.conf b/salt/files/minion.d/f_defaults.conf
index 681fa96..b3cb6b3 100644
--- a/salt/files/minion.d/f_defaults.conf
+++ b/salt/files/minion.d/f_defaults.conf
@@ -20,8 +20,7 @@
 {{ get_config('default_include', 'minion.d/*.conf') }}
 
 # master configs
-{%- if 'master' in cfg_minion -%}
-{%- if cfg_minion['master'] is not string %}
+{%- if 'master' in cfg_minion and cfg_minion['master'] is not string %}
 master:
   {% for name in cfg_minion['master'] -%}
   - {{ name }}
@@ -29,16 +28,6 @@ master:
 {%- else %}
 {{ get_config('master', 'salt') }}
 {%- endif %}
-{% elif 'master' in cfg_salt -%}
-{%- if cfg_salt['master'] is not string %}
-master:
-  {% for name in cfg_salt['master'] -%}
-  - {{ name }}
-  {% endfor -%}
-{%- else %}
-{{ get_config('master', 'salt') }}
-{%- endif -%}
-{%- endif %}
 
 # choose a random master
 {{ get_config('random_master', 'False') }}

From 8b39b3776269b61a2cf1036c7615c7498c8ab4aa Mon Sep 17 00:00:00 2001
From: abednarik <alejandro.bednarik@gmail.com>
Date: Mon, 16 Nov 2015 22:05:36 -0300
Subject: [PATCH 13/16] Replace deprecated iteritems() with items()

---
 salt/formulas.sls | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/salt/formulas.sls b/salt/formulas.sls
index 5eaaff5..b433bb5 100644
--- a/salt/formulas.sls
+++ b/salt/formulas.sls
@@ -4,7 +4,7 @@
 {% from "salt/formulas.jinja" import formulas_git_opt with context %}
 
 # Loop over all formulas listed in pillar data
-{% for env, entries in salt['pillar.get']('salt_formulas:list', {}).iteritems() %}
+{% for env, entries in salt['pillar.get']('salt_formulas:list', {}).items() %}
 {% for entry in entries %}
 
 {% set basedir = formulas_git_opt(env, 'basedir')|load_yaml %}
@@ -17,7 +17,7 @@
 {{ basedir }}:
   file.directory:
     {%- for key, value in salt['pillar.get']('salt_formulas:basedir_opts',
-                                             {'makedirs': True}).iteritems() %}
+                                             {'makedirs': True}).items() %}
     - {{ key }}: {{ value }}
     {%- endfor %}
 {% endif %}
@@ -31,7 +31,7 @@
   git.latest:
     - name: {{ baseurl }}/{{ entry }}.git
     - target: {{ gitdir }}
-    {%- for key, value in options.iteritems() %}
+    {%- for key, value in options.items() %}
     - {{ key }}: {{ value }}
     {%- endfor %}
     - require:

From 3a83533669b4a2eaa65f14bda0971e9d2c93c217 Mon Sep 17 00:00:00 2001
From: risca <risca@PCikoj>
Date: Wed, 18 Nov 2015 19:56:35 +0100
Subject: [PATCH 14/16] fixed ext_pillar according to
 https://docs.saltstack.com/en/latest/topics/development/external_pillars.html#configuration
 and master_tops according to
 https://docs.saltstack.com/en/latest/topics/master_tops/index.html

---
 salt/files/master.d/f_defaults.conf | 36 +++++++++++++++++++++++++----
 1 file changed, 32 insertions(+), 4 deletions(-)

diff --git a/salt/files/master.d/f_defaults.conf b/salt/files/master.d/f_defaults.conf
index 3da402e..54cb732 100644
--- a/salt/files/master.d/f_defaults.conf
+++ b/salt/files/master.d/f_defaults.conf
@@ -408,7 +408,19 @@ client_acl_blacklist:
 # master_tops:
 #   ext_nodes: <Shell command which returns yaml>
 #
-{{ get_config('master_tops', '{}') }}
+{% if 'master_tops' in cfg_master %}
+master_tops:
+{%- for master in cfg_master['master_tops'] -%}
+  {%- if cfg_master['master_tops'][master] is string %}
+  {{ master }}: {{ cfg_master['master_tops'][master] }}
+  {%- else %}
+  {{ master}}:
+    {%- for parameter in cfg_master['master_tops'][master] %}
+    {{ parameter }}: {{ cfg_master['master_tops'][master][parameter] }}
+    {%- endfor -%}
+  {%- endif -%}
+{%- endfor %}
+{% endif %}
 
 # The external_nodes option allows Salt to gather data that would normally be
 # placed in a top file. The external_nodes option is the executable that will
@@ -672,9 +684,25 @@ pillar_roots:
 #
 {% if 'ext_pillar' in cfg_master %}
 ext_pillar:
-{% for pillar in cfg_master['ext_pillar'] %}
-  - {{ pillar.items()[0][0] }}: {{ pillar.items()[0][1] }}
-{% endfor %}
+{%- for pillar in cfg_master['ext_pillar'] -%}
+  {%- for key in pillar -%}
+    {%- if pillar[key] is string %}
+  - {{ key }}: {{ pillar[key] }}
+    {%- elif pillar[key] is iterable and pillar[key] is not mapping %}
+  - {{ key }}:
+      {%- for parameter in pillar[key] %}
+    - {{ parameter }}
+      {%- endfor -%}
+    {%- elif pillar[key] is mapping and pillar[key] is not string %}
+  - {{ key }}: 
+      {%- for parameter in pillar[key] %}
+      {{ parameter }}: {{pillar[key][parameter]}}
+      {%- endfor %}
+    {%- else %}
+# Error in rendering {{ key }}, please read https://docs.saltstack.com/en/latest/topics/development/external_pillars.html#configuration
+    {% endif %}
+  {%- endfor -%}
+{%- endfor %}
 {% elif 'ext_pillar' in cfg_salt %}
 ext_pillar:
 {% for pillar in cfg_salt['ext_pillar'] %}

From 87f3e849d23d3dae2411015e21f66c77b7860a33 Mon Sep 17 00:00:00 2001
From: James O'Neill <hemebond@gmail.com>
Date: Sat, 5 Dec 2015 23:24:05 +1300
Subject: [PATCH 15/16] Make Debian use pkgrepo.managed and allow the repo name
 and key_url to be overridden via Pillar lookup.

---
 salt/map.jinja                   |  4 +++-
 salt/pkgrepo/debian/absent.sls   |  4 ++++
 salt/pkgrepo/debian/init.sls     | 22 ++++++----------------
 salt/pkgrepo/debian/sources.list |  2 --
 4 files changed, 13 insertions(+), 19 deletions(-)
 delete mode 100644 salt/pkgrepo/debian/sources.list

diff --git a/salt/map.jinja b/salt/map.jinja
index 3ee36c1..37e2f24 100644
--- a/salt/map.jinja
+++ b/salt/map.jinja
@@ -4,12 +4,14 @@
 {## Start with  defaults from defaults.yaml ##}
 {% import_yaml "salt/defaults.yaml" as default_settings %}
 
-{## 
+{##
 Setup variable using grains['os_family'] based logic, only add key:values here
 that differ from whats in defaults.yaml
 ##}
 {% set os_family_map = salt['grains.filter_by']({
     'Debian':  {
+      'pkgrepo': 'deb http://debian.saltstack.com/debian ' + salt['grains.get']('oscodename') + '-saltstack main',
+      'key_url': 'salt://' + slspath + '/saltstack.gpg',
       'libgit2': 'libgit2-22',
       'gitfs': {
         'pygit2': {
diff --git a/salt/pkgrepo/debian/absent.sls b/salt/pkgrepo/debian/absent.sls
index 2ace193..a3eb838 100644
--- a/salt/pkgrepo/debian/absent.sls
+++ b/salt/pkgrepo/debian/absent.sls
@@ -1,4 +1,8 @@
+{% from "salt/map.jinja" import salt_settings with context %}
+
 drop-saltstack-pkgrepo:
+  pkgrepo.absent:
+    - name: {{ salt_settings.pkgrepo }}
   file.absent:
     - name: /etc/apt/sources.list.d/saltstack.list
 
diff --git a/salt/pkgrepo/debian/init.sls b/salt/pkgrepo/debian/init.sls
index 56ae83d..4483619 100644
--- a/salt/pkgrepo/debian/init.sls
+++ b/salt/pkgrepo/debian/init.sls
@@ -1,21 +1,11 @@
-saltstack-apt-key:
-  file.managed:
-    - name: /etc/apt/trusted.gpg.d/saltstack.gpg
-    - source: salt://{{ slspath }}/saltstack.gpg
-    - user: root
-    - group: root
-    - mode: 644
+{% from "salt/map.jinja" import salt_settings with context %}
 
 saltstack-pkgrepo:
-  file.managed:
-    - name: /etc/apt/sources.list.d/saltstack.list
-    - source: salt://{{ slspath }}/sources.list
-    - user: root
-    - group: root
-    - mode: 644
-    - template: jinja
-    - require:
-      - file: saltstack-apt-key
+  pkgrepo.managed:
+    - humanname: SaltStack Debian Repo
+    - name: {{ salt_settings.pkgrepo }}
+    - file: /etc/apt/sources.list.d/saltstack.list
+    - key_url: {{ salt_settings.key_url }}
     # Order: 1 because we can't put a require_in on "pkg: salt-{master,minion}"
     # because we don't know if they are used.
     - order: 1
diff --git a/salt/pkgrepo/debian/sources.list b/salt/pkgrepo/debian/sources.list
deleted file mode 100644
index f99e426..0000000
--- a/salt/pkgrepo/debian/sources.list
+++ /dev/null
@@ -1,2 +0,0 @@
-# saltstack
-deb http://debian.saltstack.com/debian {{ grains['oscodename'] }}-saltstack main

From 6d9683ca1f902ee6c522e01d1518e060881d0ef1 Mon Sep 17 00:00:00 2001
From: James O'Neill <hemebond@gmail.com>
Date: Wed, 9 Dec 2015 23:33:00 +1300
Subject: [PATCH 16/16] Add clean_file to wipe saltstack.list contents

---
 salt/pkgrepo/debian/init.sls | 1 +
 1 file changed, 1 insertion(+)

diff --git a/salt/pkgrepo/debian/init.sls b/salt/pkgrepo/debian/init.sls
index 4483619..350713f 100644
--- a/salt/pkgrepo/debian/init.sls
+++ b/salt/pkgrepo/debian/init.sls
@@ -6,6 +6,7 @@ saltstack-pkgrepo:
     - name: {{ salt_settings.pkgrepo }}
     - file: /etc/apt/sources.list.d/saltstack.list
     - key_url: {{ salt_settings.key_url }}
+    - clean_file: True
     # Order: 1 because we can't put a require_in on "pkg: salt-{master,minion}"
     # because we don't know if they are used.
     - order: 1