change how salt is held and unheld from updates

This commit is contained in:
m0duspwnens
2021-04-15 09:42:00 -04:00
parent 427dd31fcb
commit 2f198ed9fb
2 changed files with 16 additions and 22 deletions

View File

@@ -1,5 +1,6 @@
{% import_yaml 'salt/minion.defaults.yaml' as saltminion %} {% import_yaml 'salt/minion.defaults.yaml' as saltminion %}
{% set SALTVERSION = saltminion.salt.minion.version %} {% set SALTVERSION = saltminion.salt.minion.version %}
{% set INSTALLEDSALTVERSION = salt['pkg.version']('salt-minion').split(SPLITCHAR)[0] %}
{% if grains.os == 'Ubuntu' %} {% if grains.os == 'Ubuntu' %}
{% set SPLITCHAR = '+' %} {% set SPLITCHAR = '+' %}
@@ -7,20 +8,11 @@
{% set SPLITCHAR = '-' %} {% set SPLITCHAR = '-' %}
{% endif %} {% endif %}
{% set INSTALLEDSALTVERSION = salt['pkg.version']('salt-minion').split(SPLITCHAR)[0] %}
{% set ISAIRGAP = salt['pillar.get']('global:airgap', 'False') %}
{% if grains.os|lower == 'ubuntu' %}
{% set COMMON = 'salt-common' %}
{% elif grains.os|lower in ['centos', 'redhat'] %}
{% set COMMON = 'salt' %}
{% endif %}
{% if grains.saltversion|string != SALTVERSION|string %} {% if grains.saltversion|string != SALTVERSION|string %}
{% if grains.os|lower in ['centos', 'redhat'] %} {% if grains.os|lower in ['centos', 'redhat'] %}
{% set UPGRADECOMMAND = 'yum clean all ; yum versionlock delete "salt-*" && /usr/sbin/bootstrap-salt.sh -X -s 120 -r -F -x python3 stable ' ~ SALTVERSION ~ ' ; yum versionlock add "salt-*"' %} {% set UPGRADECOMMAND = 'yum clean all ; /usr/sbin/bootstrap-salt.sh -X -s 120 -r -F -x python3 stable ' ~ SALTVERSION ~ ' && yum versionlock add "salt-*"' %}
{% elif grains.os|lower == 'ubuntu' %} {% elif grains.os|lower == 'ubuntu' %}
{% set UPGRADECOMMAND = 'apt-mark unhold salt-common ; apt-mark unhold salt-minion && /usr/sbin/bootstrap-salt.sh -X -s 120 -F -x python3 stable ' ~ SALTVERSION ~ ' ; apt-mark hold salt-common && apt-mark hold salt-minion' %} {% set UPGRADECOMMAND = '/usr/sbin/bootstrap-salt.sh -X -s 120 -F -x python3 stable ' ~ SALTVERSION ~ ' && apt-mark hold salt-common && apt-mark hold salt-minion' %}
{% endif %} {% endif %}
{% else %} {% else %}
{% set UPGRADECOMMAND = 'echo Already running Salt Minion version ' ~ SALTVERSION %} {% set UPGRADECOMMAND = 'echo Already running Salt Minion version ' ~ SALTVERSION %}

View File

@@ -9,6 +9,12 @@ include:
- salt - salt
- systemd.reload - systemd.reload
{% if "{{INSTALLEDSALTVERSION}}" != "{{SALTVERSION}}" %}
unhold_salt_packages:
module.run:
- pkg.unhold:
- 'salt-*'
install_salt_minion: install_salt_minion:
cmd.run: cmd.run:
- name: | - name: |
@@ -16,15 +22,13 @@ install_salt_minion:
exec 1>&- # close stdout exec 1>&- # close stdout
exec 2>&- # close stderr exec 2>&- # close stderr
nohup /bin/sh -c '{{ UPGRADECOMMAND }}' & nohup /bin/sh -c '{{ UPGRADECOMMAND }}' &
- onlyif: test "{{INSTALLEDSALTVERSION}}" != "{{SALTVERSION}}" {% endif %}
salt_minion_package: {% if "{{INSTALLEDSALTVERSION}}" == "{{SALTVERSION}}" %}
pkg.installed: hold_salt_packages:
- pkgs: module.run:
- {{ COMMON }} - pkg.hold:
- salt-minion - 'salt-*'
- hold: True
- onlyif: test "{{INSTALLEDSALTVERSION}}" == "{{SALTVERSION}}"
set_log_levels: set_log_levels:
file.append: file.append:
@@ -46,11 +50,9 @@ salt_minion_service_unit_file:
- module: systemd_reload - module: systemd_reload
- listen_in: - listen_in:
- service: salt_minion_service - service: salt_minion_service
- onlyif: test "{{INSTALLEDSALTVERSION}}" == "{{SALTVERSION}}"
salt_minion_service: salt_minion_service:
service.running: service.running:
- name: salt-minion - name: salt-minion
- enable: True - enable: True
- onlyif: test "{{INSTALLEDSALTVERSION}}" == "{{SALTVERSION}}" {% endif %}