Last active
July 27, 2016 14:58
-
-
Save aphor/01acf8d13539be45f7d27378aef88c18 to your computer and use it in GitHub Desktop.
SaltStack salt-cloud event reactor driven orchestration for automatic complex minion initialization
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## /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 }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## /etc/salt/master.d/reactor.conf | |
reactor: | |
- 'salt/cloud/*/created': | |
- /srv/salt/reactor/common/new_cloud_minion.sls |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## /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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks: Nate Brooks, for helping with this.