guettli
guettli

Reputation: 27806

Update pillar data in custom module?

I would like to update the pillar data in a custom module.

Background: I would like to set some default values.

This would make the code in jinja simpler, since I could use one place to create defaults (in custom module) and N conditionless usages of the pillar data (in jinja).

For example, up to now the code looks like this (at several places):

{% if pillar.database_replication|default(False) %}

I would like to set the default in a custom module.

Then this would be enough:

{% if pillar.database_replication %}

My goal is to make sls files simpler.

I use salt version 2019.2.0.

Upvotes: 0

Views: 287

Answers (1)

daks
daks

Reputation: 883

I think what you can do is have a 'defaults' pillar file, which is loaded before all others.

Something like this in pillar top.sls

base:
  '*':
     - defaults

# rest of pillar to load

Then you can have in defaults.sls

# default pillars for all minions
database_replication: False

Then:

  • if a minion do not have a specific value: you get the default one
  • if a minion have a specific value, it's set after loading the 'defaults' so it overrides it, and you get the minion specific value

Upvotes: 1

Related Questions