From a451150ee5bb2d18d21b80c9da5d565a6195e2f9 Mon Sep 17 00:00:00 2001 From: Julien Leproust Date: Fri, 27 Nov 2020 16:18:46 +0100 Subject: [PATCH] Allow dicts as well as lists in wanted and others This can also be used as a workaround for the impossibility of merging lists in the pillar (https://github.com/saltstack-formulas/packages-formula/issues/21). --- packages/pkgs.sls | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/packages/pkgs.sls b/packages/pkgs.sls index 2be9658..9d40dd6 100644 --- a/packages/pkgs.sls +++ b/packages/pkgs.sls @@ -20,7 +20,18 @@ include: ### PRE-REQ PKGS (without these, some of the WANTED PKGS will fail to install) pkg_req_pkgs: pkg.installed: + {%- if req_packages is mapping %} + - pkgs: + {%- for p, v in req_packages.items() %} + {%- if v %} + - {{ p }}: {{ v }} + {%- else %} + - {{ p }} + {%- endif %} + {%- endfor %} + {%- else %} - pkgs: {{ req_packages | json }} + {%- endif %} {%- if req_states %} - require: {%- for dep in req_states %} @@ -35,7 +46,11 @@ held_pkgs: {%- if held_packages is mapping %} - pkgs: {%- for p, v in held_packages.items() %} + {%- if v %} - {{ p }}: {{ v }} + {%- else %} + - {{ p }} + {%- endif %} {%- endfor %} {%- else %} - pkgs: {{ held_packages | json }} @@ -54,7 +69,18 @@ held_pkgs: wanted_pkgs: pkg.installed: + {%- if wanted_packages is mapping %} + - pkgs: + {%- for p, v in wanted_packages.items() %} + {%- if v %} + - {{ p }}: {{ v }} + {%- else %} + - {{ p }} + {%- endif %} + {%- endfor %} + {%- else %} - pkgs: {{ wanted_packages | json }} + {%- endif %} {%- if grains['os_family'] not in ['Suse'] %} - hold: false {%- endif %} @@ -69,6 +95,13 @@ wanted_pkgs: unwanted_pkgs: pkg.purged: + {%- if unwanted_packages is mapping %} + - pkgs: + {%- for p, v in unwanted_packages.items() %} + - {{ p }} + {%- endfor %} + {%- else %} - pkgs: {{ unwanted_packages | json }} + {%- endif %} {%- endif %}