Skip to content

Instantly share code, notes, and snippets.

@aphor
Last active July 27, 2016 14:58
Show Gist options
  • Save aphor/01acf8d13539be45f7d27378aef88c18 to your computer and use it in GitHub Desktop.
Save aphor/01acf8d13539be45f7d27378aef88c18 to your computer and use it in GitHub Desktop.
SaltStack salt-cloud event reactor driven orchestration for automatic complex minion initialization
## /salt/reactor/common/new_cloud_minion.sls
post_bootstrap_setup:
runner.state.orchestrate:
- mods: orch.selinux_relabel_reboot_highstate
- pillar:
event_tag: {{ tag }}
event_data: {{ data }}
## /etc/salt/master.d/reactor.conf
reactor:
- 'salt/cloud/*/created':
- /srv/salt/reactor/common/new_cloud_minion.sls
## /srv/salt/orch/selinux_relabel_reboot_highstate.sls
{% set tag = salt.pillar.get('event_tag') %}
{% set data = salt.pillar.get('event_data') %}
{% set minion_name = data.get('name') %}
ping_minion:
salt.function:
- tgt: '{{ minion_name }}'
- name: test.ping
set_selinux_permissive:
salt.state:
- tgt: '{{ minion_name }}'
- sls:
- selinux
- require:
- salt: ping_minion
getenforce_permissive:
salt.function:
- tgt: '{{ minion_name }}'
- name: cmd.run
- arg: ['getenforce && getenforce | grep permissive > /dev/null || echo SELinux not permissive']
- watch:
- salt: set_selinux_permissive
selinux_relabel_reboot:
salt.function:
- tgt: '{{ minion_name }}'
- name: cmd.run
- arg:
- 'shutdown -r +1 SELinux relabel'
- onfail:
- salt: set_selinux_permissive
- salt: getenforce_permissive
wait_for_reboots:
salt.wait_for_event:
- name: salt/minion/{{ minion_name }}/start
- id_list:
- {{ minion_name }}
- watch:
- salt: selinux_relabel_reboot
finish_setup:
salt.state:
- tgt: '{{ minion_name }}'
- highstate: True
- watch:
- salt: wait_for_reboots
@aphor
Copy link
Author

aphor commented Jul 27, 2016

Thanks: Nate Brooks, for helping with this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment