salt icon indicating copy to clipboard operation
salt copied to clipboard

Add SaLt State arguments

Open Tassatux opened this issue 14 years ago • 15 comments

It might be useful if we can pass arguments to a salt state for use them in template, like Puppet parameterized classes.

For example, in top.sls:

base:
  '*':
    - users:
      - shell: '/bin/zsh'
    - apache.vhost:
      - servername: 'mywebsite'
      - docroot: '/var/www/mywebsite'

Or in the YAML returned by an external node classifier:

classes:
  - users:
    - shell: '/bin/zsh'
  - apache.vhost:
    - servername: 'mywebsite'
    - docroot: '/var/www-mywebsite'
environment: 'base'

This will allow to have generic sls and handle minions with slight changes in their configuration.

Tassatux avatar Mar 20 '12 22:03 Tassatux

Thanks for opening this up, I have been trying to figure out the best way to handle this one

thatch45 avatar Mar 20 '12 22:03 thatch45

Since you're familar with puppet's parameterized classes and ENC (salt supports the puppet ENC yaml), perhaps you could also consider using pillar in the short term?

It is vaguely conceptually similar to puppet's extlookup mechanism.

SEJeff avatar Apr 03 '12 01:04 SEJeff

Well, pillar does not support defaults, I am mostly reading this as being able to set defaults somewhere for state decs.

thatch45 avatar Apr 03 '12 02:04 thatch45

Right. I understand. Just saying it could be used to support something vaguely similar until salt natively supports this functionality.

SEJeff avatar Apr 03 '12 02:04 SEJeff

yes :) I know how to add defaults in the code, it is easy there, I am just not quite sure how I want them to be represented in the sls data yet

thatch45 avatar Apr 03 '12 02:04 thatch45

5d74fe6463539bc26ad77b4d344089b41d5723e5

I don't think this is a fix here, but it is a step towards this. My big debate is how to best represent the data, since the originally suggested format would not do it the way I would like.

I am moving this ticket off for now since we have a partial fix, barring any better ideas on how to do this.

thatch45 avatar Apr 06 '12 19:04 thatch45

I would also find this very useful. I was asked +1 this in IRC :).

ryan-lane avatar Jun 08 '12 16:06 ryan-lane

I just implemented something similar to what's asked here, using a custom renderer. It may or may not be what you want.

kjkuan avatar Sep 25 '12 20:09 kjkuan

I would also love to see this. This is especially useful for "many similar" scenarios.

FWIW I've currently resorted to solving this via shim states and jinja includes:

In states/top.sls:

'matcher1':
  - foo.m1
'matcher2':
  - foo.m2

foo/m1.sls shim:

{% set key = "m1" %}
{% include "foo/_common.sls" %}

foo/m2.sls shim:

{% set key = "m2" %}
{% include "foo/_common.sls" %}

foo/_common.sls:

.... stuff making use of jinja variable "key" ...
.... it's important that any state IDs created are uniquified by including {{key}} in their name ....

minaguib avatar Apr 28 '13 19:04 minaguib

You can use the new get methods to set defaults via pillar now, does this solve the issue for you?

thatch45 avatar Apr 29 '13 01:04 thatch45

As @thatch45 asked, do the new get methods provide a solution?

terminalmage avatar Jun 18 '13 23:06 terminalmage

As we havent had a reply in a few months, I'm going to close this for now. Feel free to comment if those get methods do not provide a solution for your needs.

basepi avatar Jun 19 '13 17:06 basepi

I think this isn't really about being able to specify defaults. OP wants to parameterize the classes used in top.sls. I believe many people want this, myself included.

As I understand it, people want to write a vhost class that abstracts how vhosts are configured, instead of how one specific vhost is configured, so it can be used multiple times in the same host, or in other hosts, to specify different vhosts:

base:
  'web':
    - vhost:
      servername: wiki.domain
      path: /var/www/wiki
    - vhost:
      servername: www.domain
      path: /var/www/html

I believe that get method does not provide a solution to this scenario. Is there a more elegant solution to this problem? The point here is that one may have hundreds of hosts, each one with dozens of vhosts; people don't want to create a sls file for each vhost.

dimasmjunior avatar Jul 21 '13 00:07 dimasmjunior

That's why you put the minion specific information in pillar On Jul 20, 2013 6:12 PM, "dimasmjunior" [email protected] wrote:

I think this isn't really about being able to specify defaults. OP wants to parameterize the classes used in top.sls. I believe many people want this, myself included.

As I understand it, people want to write a vhost class that abstracts how vhosts are configured, instead of how one specific vhost is configured, so it can be used multiple times in the same host, or in other hosts, to specify different vhosts:

base: 'web': - vhost: servername: wiki.domain path: /var/www/wiki - vhost: servername: www.domain path: /var/www/html

I believe that get method does not provide a solution to this scenario. Is there a more elegant solution to this problem? The point here is that one may have hundreds of hosts, each one with dozens of vhosts; people don't want to create a sls file for each vhost.

— Reply to this email directly or view it on GitHubhttps://github.com/saltstack/salt/issues/976#issuecomment-21302759 .

UtahDave avatar Jul 21 '13 00:07 UtahDave

I think "reclass" implements this behavior, in a way: http://reclass.pantsfullofunix.net/

As to why some users would prefer to do it in this way, instead of using pillar, please refer to this talk given at DebConf13: http://reclass.pantsfullofunix.net/refs.html?highlight=video

dimasmjunior avatar Sep 04 '13 02:09 dimasmjunior