From 98ad87a0014114f79fde1854dfb3731fad772ac4 Mon Sep 17 00:00:00 2001 From: hatifnatt Date: Wed, 18 Mar 2020 22:49:28 +0300 Subject: [PATCH] feat(package): use apt-pinning to pin specific package version Available only on Debian family OS-es --- pillar.example | 4 ++++ salt/defaults.yaml | 1 + salt/master.sls | 5 +++++ salt/minion.sls | 5 +++++ salt/pin.sls | 22 ++++++++++++++++++++++ 5 files changed, 37 insertions(+) create mode 100644 salt/pin.sls diff --git a/pillar.example b/pillar.example index 38ea094..91d5d8a 100644 --- a/pillar.example +++ b/pillar.example @@ -24,6 +24,10 @@ salt: # Optional: set salt version (if install_packages is set to true) version: 2017.7.2-1.el7 + # Pin version provided under 'version' key by using apt-pinning + # available only on Debian family OS-es + pin_version: false + # to overwrite map.jinja salt packages lookup: salt_master: 'salt-master' diff --git a/salt/defaults.yaml b/salt/defaults.yaml index 2621ad7..d4dcaf1 100644 --- a/salt/defaults.yaml +++ b/salt/defaults.yaml @@ -3,6 +3,7 @@ --- salt: version: '' + pin_version: false py_ver: '' ## py2 is default rootuser: root rootgroup: root diff --git a/salt/master.sls b/salt/master.sls index a6fdeac..665c302 100644 --- a/salt/master.sls +++ b/salt/master.sls @@ -2,6 +2,11 @@ {%- from tplroot ~ "/map.jinja" import salt_settings with context %} {%- from tplroot ~ "/libtofs.jinja" import files_switch with context %} +{% if salt_settings.pin_version and salt_settings.version and grains.os_family|lower == 'debian' %} +include: + - .pin +{% endif %} + salt-master: {% if salt_settings.install_packages %} pkg.installed: diff --git a/salt/minion.sls b/salt/minion.sls index e6981d3..2cf44c7 100644 --- a/salt/minion.sls +++ b/salt/minion.sls @@ -2,6 +2,11 @@ {%- from tplroot ~ "/map.jinja" import salt_settings with context %} {%- from tplroot ~ "/libtofs.jinja" import files_switch with context %} +{% if salt_settings.pin_version and salt_settings.version and grains.os_family|lower == 'debian' %} +include: + - .pin +{% endif %} + {% if salt_settings.install_packages and grains.os == 'MacOS' %} download-salt-minion: {% if salt_settings.salt_minion_pkg_source %} diff --git a/salt/pin.sls b/salt/pin.sls new file mode 100644 index 0000000..abd824a --- /dev/null +++ b/salt/pin.sls @@ -0,0 +1,22 @@ +{%- set tplroot = tpldir.split('/')[0] %} +{%- from tplroot ~ "/map.jinja" import salt_settings with context %} + +{% if salt_settings.pin_version and salt_settings.version and grains.os_family|lower == 'debian' %} +salt-pin-version: + file.managed: + - name: /etc/apt/preferences.d/salt + - contents: | + # This file managed by Salt, do not edit by hand!! + Package: salt* + Pin: version {{ salt_settings.version }} + Pin-Priority: 1000 + # Order: 2 because we can't put a require_in on "pkg: salt-{master,minion}" + # because we don't know if they are used, and 'order: 1' already occupied by salt-pkgrepo + - order: 2 + +{% elif grains.os_family|lower != 'debian' %} +salt-pin-version: + test.show_notification: + - name: Available on Debian family OS-es only + - text: Apt pinning available only on Debian based distributives +{% endif %}