orchestrate runner - batch multiple state apply across multiple groups of nodes.

212 views
Skip to first unread message

Goran Stankovski

unread,
Jun 2, 2016, 3:29:08 AM6/2/16
to Salt-users
Hi all,

As a salt noob, trying to find out information on the orchestrate runner.

I have multiple groups of nodes, to which I would like to apply different states. These nodes are independent, and as a result, can have their states applied in parallel.

How could this be achieved using the orchestration runner.

High level overview of orchestration

prerequisite_stuff:
  salt.state:
    - tgt: '*'

    - sls:

      - do_prereq_stuff


# Now I want to apply the following states across multiple groups of nodes

setup_node_group_a:
  salt.state:
    - tgt: 'role: group_a'

    - sls:

      - do_group_a_stuff


setup_node_group_b:
  salt.state:
    - tgt: 'role: group_b'

    - sls:

      - do_group_b_stuff


setup_node_group_c:
  salt.state:
    - tgt: 'role: group_c'

    - sls:

      - do_group_c_stuff



So, do the above states for a,b, and c apply to their respective nodes in parallel (meaning, does setup_node_group_a|b|c all run on their nodes in parallel, or are the states applied in sequence across the corresponding node groups)? 
If not, how can this "batch or parallel flow" be achieved from an orchestrate runner?

Thanks in advance.

Sandy

unread,
Jun 7, 2016, 3:51:32 PM6/7/16
to Salt-users
Hi,

I too am a newbie, so please take this with a grain of salt :-)

On the other hand, I too am interested in the possible answers to this question.  So to get some posts going...

Maybe create a fake wrapper state.  But this may not be what you are looking for (not abiding by the contraints of the question):

$ cat state/base/orch/test.sls

call wrapper state:

 salt.state:

   - tgt: '*'

   - sls:

     - orch/state-wrapper


And place something like the below in state-wrapper:

$ cat state/base/orch/state-wrapper.sls

{% if grains.id == 'foo' %}

run different states in parallel:

 cmd.run:

    - name: echo "one"


{% elif grains.id == 'bar' %}

run different states in parallel:

 cmd.run:

   - name: echo "two"


{% elif grains.id == 'baz' %}

run different states in parallel:

 cmd.run:

   - name: echo "three"


{% else %}

run different states in parallel:

 cmd.run:

   - name: echo "uh-oh"


{% endif %}

Enter code here...

In other words, different states on different nodes that want to be or can be executed in parallel at orchestration time (as opposed to highstate time) can leverage a non-orchestration wrapper state.

[To address the example below, switch the grains.id test above with the desired test from below]

Hope this helps,
-sandy

Travis Mehlinger

unread,
Jun 23, 2016, 12:00:20 PM6/23/16
to Salt-users
That approach won't get you anything because orchestration executes on the master. Those grains will be the master's grains, not individual minions' grains, so it will only render one of those branches (assuming that grain even exists on the master), then apply that to whichever minions actually match that branch.

However, you can use pillar to make this work by matching grains in the pillar top and using pillar values to control which states you apply. You could then dynamically include a state based on the value set in pillar:


# pillar/base/top.sls
base:
  'roles:group_a':
    - group_a
  'roles:group_b':
    - group_b
  'roles:group_c':
    - group_c


# pillar/base/group_a.sls
group_state_to_apply: group_a_state


# pillar/base/group_b.sls
group_state_to_apply: group_b_state


# pillar/base/group_c.sls
group_state_to_apply: group_c_state


# states/base/orch/node_groups.sls
apply_state_to_all_roles:
  salt.state:
    - tgt: 'G@roles:group_a or G@roles:group_b or G@roles:group_c'
    - tgt_type: compound
    - sls:
      - group_wrapper


# states/base/group_wrapper.sls
include:
  - {{ pillar['group_state_to_apply'] }}


Disclaimer: I just slapped this together in a few minutes and haven't tested it. Pretty sure that should work, though.

Reply all
Reply to author
Forward
0 new messages