Ordering SLS and include statements

713 views
Skip to first unread message

Stephen Wood

unread,
Oct 7, 2013, 7:10:23 PM10/7/13
to salt-...@googlegroups.com
At the top of my sls file I am using "include" to form a sort of inheritance.

include:
  - base_install

...rest of installation...

I can see from the execution log that the base_install sls file is actually being executed nearly last.

If I want base_install (which does a lot of stuff to put the machine in a certain state) is a require for everything else that comes after it, how would this work? Would I need to add:

require:
  - base_install

to everything?

Also, will state_auto_order affect this? I set state_auto_order to True in my master config but it doesn't seem to make any difference. I'm using 0.17.0-500-g85019e7

--

Nick Davis

unread,
Oct 7, 2013, 7:20:34 PM10/7/13
to salt-...@googlegroups.com
You have 2 options:

1. Have everything include a require statement like you suggest.

OR

2. Add 'order: 1' to your state that needs to go first.

See the end of this doc:

Nick


--
You received this message because you are subscribed to the Google Groups "Salt-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to salt-users+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Stephen Wood

unread,
Oct 7, 2013, 8:06:20 PM10/7/13
to salt-...@googlegroups.com
Nick, thanks for your update.

Would the order: 1 come from within my top.sls or my actual state files?

For example, in my include statement should it look like this?

include:
  - base_install:
    - order: 1

Nick Davis

unread,
Oct 7, 2013, 8:44:22 PM10/7/13
to salt-...@googlegroups.com
No, you do not perform any ordering in top.sls. Ordering (and require) apply to states, so you cannot use them in an include declaration either. However, you can achieve the same thing as your example using 'extend'.


Option 1: Use order as part of a state
# python/init.sls #
# You want pip to be installed before anything else, so you want this state to be run before any others and assign it an order of 1.
install_pip:
  pkg.installed:
    - name: python-pip
    - order: 1

Option 2: Use order with extend in another state:
# fun/init.sls
# Same result as above, but for some reason you don't always need pip to be installed first, so you leave the option open to use that python state with ordering other than 1. Thus, you are extending the python state to apply your chosen order.
include:
  - python

extend:
  install_pip:
    pkg: 
      - order: 1

Option 3: Have every state declaration require the state id:
include:
  - python

<your state id>:
  <your function>:
     - <other params>
     - require:
       - pkg: install_pip

Hope that helps,
Nick

Stephen Wood

unread,
Oct 7, 2013, 8:58:02 PM10/7/13
to salt-...@googlegroups.com
Nick,

Thanks for the replace. Isn't auto_state_order suppose to solve this problem by forcing the include sls to be executed first if it's at the top of my sls?

I am wondering if maybe the way I am going about creating these state files is fundamentally flawed. I hoped to create a base_install.sls skeleton that I could build off of with inheritance/include, but it doesn't seem to work like that.

--

Nick Davis

unread,
Oct 7, 2013, 11:53:31 PM10/7/13
to salt-...@googlegroups.com
Yes. If you have salt >= 0.17.0 it is supposed to install them in the order they are defined in the sls file. I haven't tried it though.
 All of my states still rely on the order/require statements, because I haven't gone back to change them.

Personally, I've gone through many iterations of my salt states. Over time, you learn more and salt gets new features, so you will probably re-visit your state design later.

The thing I generally do is to make each state as simple as possible. Then I create additional states that have the single purpose of combining other states into an ordered grouping. Then I have my top.sls call that one state to kick off the whole orchestra. I'm sure there are other methods.

Nick
Reply all
Reply to author
Forward
0 new messages