Skip to content

Instantly share code, notes, and snippets.

@srikiraju
Created December 19, 2017 19:47
Show Gist options
  • Save srikiraju/d44f08b01666d9523d37694ca0cdeed5 to your computer and use it in GitHub Desktop.
Save srikiraju/d44f08b01666d9523d37694ca0cdeed5 to your computer and use it in GitHub Desktop.
Quick upgrade automation with salt
{# Getting this passed in through a runner #}
{% set upgrade_minions = pillar.args.upgrade_minions %}
{% macro wait_for(id_list, req) %}
wait_for_reboot:
salt.wait_for_event:
- name: salt/minion/*/start
- timeout: 300
- id_list:
{% for id in id_list -%}
- {{ id }}
{%- endfor %}
- require:
- salt: {{ req }}
{%- endmacro %}
{# % set upgrade_minions_match = salt['match.compound'](upgrade_minions ~ deployable) % #}
{% set upgrade_minions_match = salt['cmd.run']('salt ' + upgrade_minions + ' --out newline_values_only grains.get id' %}
{# % set upgrade_minions_match = salt.saltutil.cmd(tgt=upgrade_minions, fun='grains.get', arg=('id', )) % #}
run_upgrade:
salt.state:
- tgt: "{{ upgrade_minions }}"
- tgt_type: compound
- sls:
- setup.deregister-upgrade-apt
{{ wait_for(upgrade_minions_match, 'run_upgrade') }}
post_upgrade:
salt.state:
- tgt: "{{ upgrade_minions }}"
- tgt_type: compound
- sls:
- setup.post-upgrade
- require:
- salt: wait_for_reboot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment