Add SaLt State arguments
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.
Thanks for opening this up, I have been trying to figure out the best way to handle this one
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.
Well, pillar does not support defaults, I am mostly reading this as being able to set defaults somewhere for state decs.
Right. I understand. Just saying it could be used to support something vaguely similar until salt natively supports this functionality.
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
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.
I would also find this very useful. I was asked +1 this in IRC :).
I just implemented something similar to what's asked here, using a custom renderer. It may or may not be what you want.
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 ....
You can use the new get methods to set defaults via pillar now, does this solve the issue for you?
As @thatch45 asked, do the new get methods provide a solution?
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.
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.
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 .
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