Numb
Numb

Reputation: 11

For saltstack,how to get nodegroup of the minion in the jinjia template?

I want to get nodegroup of the minion in the jinjia template or pillar.How can I do it?

e.g. /path/jinjia_template_for_nginx.conf

{% if nodegroup == 'web' %}//nodegroup == get the minion's group
param_xxx 1;
{% else %}
param_xxx 2;
{% endif %}

Upvotes: 1

Views: 1685

Answers (1)

ahus1
ahus1

Reputation: 5950

AFAIK there is no way to get the node group of the current minion via a grain or a pillar directly. You can choose to export your master's configuration to you minion using pillar_opts = True in your master configuration, but any salt-call pillar.get master:nodegroups:web will get you an unexpanded list of hosts that is if no use here.

I suggest you create a pillar for this that maches on the group ...

# pillar top.sls
base:
  web:
    - match: nodegroup
    - webserver

Then set a value of your choice ...

# webserver.sls
mygroup: web

And then use it in the template ...

# nginx.conf
{% if salt['pillar.get']('mygroup', 'unknown') == 'web' %}
param_xxx 1;
{% else %}
param_xxx 2;
{% endif %}

I hope this helps.

Looking at the functionality of nodegroups, pillars and compound matchers you could consider configuring only pillar information and either skip nodegroups, or use a compound matcher using pillar data to define your nodegroups.

Upvotes: 2

Related Questions