SaltStack: how do I repeat other states with context?

0 votes

I’ve created a state for API

 I would like to turn it into a template and execute it several times per minion, with variables supplied from pillar - i.e something like.

    {% for apiserver in pillar.apiservers %}
      include apiserver_template.sls, locals: apiserver.config
    {% endfor %}

where apiserver_template will work with context supplied to it, with apiserver.config having all config data for each API instance. I know syntax is wrong but hopefully I am communicating the idea - ideally, something like executing ruby partials with supplying local variables.

How is it done properly in saltland?

Jul 10, 2018 in Other DevOps Questions by Nilesh
• 6,880 points
63 views

1 answer to this question.

0 votes

In your case it’ll look something like this

 

{% macro api_server(git_repo, python_venv_path, python_venv_requirements) %}

{{python_venv_path}}:

  virtualenv.managed:

    - system_site_packages: False

    - requirements: salt://{{python_venv_requirements}}

 

{{git_repo}}:

  git.latest:

    - name: {{git_repo}}

{% endmacro %}

 

Assuming you have a pillar apiservers where each api server has git_repo, python_venv_path and python_venv_requirements values, you can use the macro like this:

{% for server in salt.pillar.get('apiservers', []) %}

{{ api_server(server['git_repo'], server['python_venv_path'], server['python_venv_requirements']) }}

{% endfor %}

answered Jul 10, 2018 by Kalgi
• 2,620 points

Related Questions In Other DevOps Questions

0 votes
1 answer

How do I share Build Definitions across Projects in Visual Studio Online?

VSTS does not support sharing build definitions ...READ MORE

answered Jul 5, 2018 in Other DevOps Questions by DareDev
• 6,810 points
33 views
0 votes
1 answer

how do i make apache2 site point outside the folder in ubuntu?

in apche2 configuration file u have to ...READ MORE

answered Jul 6, 2018 in Other DevOps Questions by Kalgi
• 41,760 points
37 views
0 votes
1 answer

How do I enable Slack for Bluemix DevOps services beta

Here is where you can take help ...READ MORE

answered Jul 11, 2018 in Other DevOps Questions by Atul
• 10,240 points
45 views
0 votes
1 answer

How do I set variable if a specific package version is installed in CFEngine?

Here is what you can do.Just use packagesmatching to ...READ MORE

answered Jul 12, 2018 in Other DevOps Questions by Atul
• 10,240 points
87 views
0 votes
1 answer
+13 votes
2 answers

Git management technique when there are multiple customers and need multiple customization?

Consider this - In 'extended' Git-Flow, (Git-Multi-Flow, ...READ MORE

answered Mar 26, 2018 in DevOps & Agile by DragonLord999
• 8,380 points
181 views
0 votes
1 answer

How does horizontal scaling decrease load of a system?

If there are spare CPU cycles and ...READ MORE

answered Jul 11, 2018 in Other DevOps Questions by Kalgi
• 2,620 points
25 views
0 votes
1 answer