Question

when using puppet I used to do something like the following:

    class common_vars {
        $some_var = calculate_some_var()
    }

    class A {
        Class[common_vars] -> Class[A]
        do_something_with($common_vars::some_var)
    }

    class B {
        Class[common_vars] -> Class[B]
        do_something_else_with($common_vars::some_var)
    }

I'm now looking for something similar in saltstack.

I used this for example for setting up network services which are bound to a specific network address. I first setup networking, then calculate some common addresses, then setup the network services.

Instead of calculating these addresses (where different services may share the same address) over and over again in each state-file, I'd like to calculate them once, and reuse them later on.

Was it helpful?

Solution

I would do this in Salt's Pillar.

Here's a walkthrough: http://docs.saltstack.com/topics/tutorials/pillar.html

OTHER TIPS

This probably goes beyond Salts YAML renderer. Instead you could write your SLS in pure python, giving you the ability to to write functions, classes etc and return the state data. For example:

some_var = lambda: 1 + 2    

def do_something():
    global(some_var)
    return some_var() + 5  # 8

def do_something_else():
    global(some_var)
    return some_var() + 10  # 13

def run():
    return {
        '/home/user/somefile.txt': {
            'file.append': [
                {'text': do_something()},
             ]
        },
        '/home/user/some_other.txt': {
            'file.append': [
                {'text': do_something_else()},
             ]
        },
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top