Transfer of variables with inclusion in the salt stack

I have several states that are almost the same. They all deploy the project, create virtualenv, and configure the supervisor. The only difference is repo, project name and some additional actions.

A lot of code is duplicated. Is it possible to put the same parts in a file and include it with additional variables?

In Ansible, this can be done as follows:

tasks: - include: wordpress.yml vars: wp_user: timmy ssh_keys: - keys/one.txt - keys/two.txt 
+2
salt stack
source share
2 answers

This question is similar to this.

If I understand your question correctly - I believe that the best way to achieve what you want is Salt Macros .

In this case, most of your state will go to macros with placeholders, such as:

 # lib.sls {% macro create_user(user, password) %} {{user}}: user.present: - home: /home/{{user}} - password: {{password}} {% endmacro %} 

Then your condition will look like this:

 # john.sls {% from 'lib.sls' import create_user with context %} {{ create_user('john', '<password hash>') }} 

and

 # jane.sls {% from 'lib.sls' import create_user with context %} {{ create_user('john', '<password hash>') }} 
+5
source share

As I found out, there is another way to archive it without messing around with templates (more Ansible way). Create an abstract state of "python-project". Then create specific roles and create various supports for these roles:

<strong> salt /top.sls:

 base: 'roles:python-project-1': - match: grain - python-project 'roles:python-project-2': - match: grain - python-project 

Post /top.sls:

 base: 'roles:python-project-1': - match: grain - common-pillars - pillars-for-the-first 'roles:python-project-2': - match: grain - common-pillars - pillars-for-the-second 

Composition:

 pillar/top.sls pillar/common-pillars/init.sls pillar/pillars-for-the-first/init.sls pillar/pillars-for-the-second/init.sls salt/top.sls salt/python-project/init.sls 
0
source share

All Articles