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,900 points
48 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
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,560 points
21 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
• 35,800 points
20 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,200 points
28 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,200 points
51 views
0 votes
1 answer
+13 votes
2 answers
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
16 views
0 votes
1 answer

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.