rrFeng
rrFeng

Reputation: 191

How to set saltstack pillar by minion id?

Considering there is a state file: kafka.sls for deploying and configuring a kafka cluster.

Now we need some pillar data for configuration, for global configuration, we can put it in a pillar/kafka.sls like these:

kafka:
  cluster:
    name: my-kafka-cluster
  log_dir: /data/kafka/
  autocreate_topic: true

And in the top.sls

base:
  'role:Kafka':
    - kafka

Now we need different configuration for each broker: broker.id

Where should I put broker.id in? The only way I know is using if/else in the pillar. But it is really bad practice.

kafka:
  cluster:
    name: my-kafka-cluster
  log_dir: /data/kafka/
  autocreate_topic: true
  broker_id: {% if grains.get['minion_id'] == HOSTNAME ... %}   

OR in the top.sls:

base:
  'role:Kafka':
     - kafka
  'minion_id':
     - kafka_settings_for_minion_id

What's the best way?

Upvotes: 0

Views: 1270

Answers (1)

laocius
laocius

Reputation: 842

You can put the pillar data file for each minion under pillar_roots/minions/ and then add the following code to you top file

base:
  '*':
    - minions.{{ grains['id'] }}

Upvotes: 3

Related Questions