salt-states/chocolatey-packages.sls

34 lines
1.3 KiB
Plaintext
Raw Permalink Normal View History

include:
- chocolatey
{% import_yaml "./packages.yaml" as packages %}
# Install packages which are not installed
{% set installed_pkg_lines = salt['cmd.run']("if (Get-Command choco -ErrorAction SilentlyContinue) { choco list --local-only -r }", shell="powershell").splitlines() %}
{% set installed_pkg = installed_pkg_lines|map('method_call', 'split', '|', 1)|map(attribute=0)|map('lower')|list %}
{% for pkg in packages|difference(installed_pkg) %}
"install {{ pkg }}":
chocolatey.installed:
- name: {{ pkg }}
{% if pkg in packages and packages[pkg] %}
{{ packages[pkg] | dict_to_sls_yaml_params | indent }}
{% endif %}
- require:
- sls: chocolatey
{% endfor %}
# Update only packages that need updating
{% set outdated_pkg_lines = salt['cmd.run']("if (Get-Command choco -ErrorAction SilentlyContinue) { choco outdated -r --ignore-unfound }", shell="powershell").splitlines() %}
{% set outdated_pkg = outdated_pkg_lines|map('method_call', 'split', '|', 1)|map(attribute=0) %}
{% for pkg in outdated_pkg|difference(['chitubox', 'sketchup', 'autodesk-fusion360']) %}
"update {{ pkg }}":
module.run:
- chocolatey.upgrade:
- name: "{{ pkg }}"
{% if pkg in packages and packages[pkg] %}
{{ packages[pkg] | dict_to_sls_yaml_params | indent }}
{% endif %}
- require:
- chocolateyBootstrap
{% endfor %}