Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(package): use apt-pinning to pin specific package version #458

Merged
merged 2 commits into from
Apr 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# https://help.github.com/en/github/creating-cloning-and-archiving-repositories/about-code-owners

# FILE PATTERN OWNER(S)
* @saltstack-formulas/wg
salt/formulas.sls @sticky-note @myii
salt/pin.sls @hatifnatt
4 changes: 4 additions & 0 deletions pillar.example
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
1 change: 1 addition & 0 deletions salt/defaults.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
---
salt:
version: ''
pin_version: false
py_ver: '' ## py2 is default
rootuser: root
rootgroup: root
Expand Down
5 changes: 5 additions & 0 deletions salt/master.sls
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 5 additions & 0 deletions salt/minion.sls
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
Expand Down
22 changes: 22 additions & 0 deletions salt/pin.sls
Original file line number Diff line number Diff line change
@@ -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 %}