Pim Jeursen
Pim Jeursen

Reputation: 3

Get minion ip in Saltstack Jinja template filtered by pillar

I'm currently busy creating a automated netdata ephemeral cluster, which means I have a master netdata node which the slaves connect to. I've found a similar question + answer, but instead of using a grain I use pillars.

I'm trying to get the Netdata master ip, and distribute it to the minions running Netdata via a Template. But this can be applied to other master-slave configs as well (e.g. postgres, elasticsearch etc)

I'm assigning roles via pillars. So my pillar file looks like:

server:
  roles:
    - netdata-master
    - grafana

And my jinja template:

{% set netdatamaster = ..... %}
[stream]
  # stream metrics to another netdata
  enabled = yes

  # the IP and PORT of the master
  destination = {% netdatamaster %}:19999

Now I want the var netdatamaster to contain the ipv4 adres of the Netdata master. I just can't figure out a way to do this.

Upvotes: 0

Views: 1000

Answers (1)

Gijs Brandsma
Gijs Brandsma

Reputation: 983

You can use the Salt Mine for this.

First add a mine_function to your netdata-master server. This can be configured in pillar or in the minion config file.

mine_functions:
  eth0_ip_addrs:
    mine_function: network.ip_addrs
    interface: eth0

The above mine_function enables other minions to request the value of network.ip_addrs for your netdata-master server.

You can request this data in different ways:

  • From the cli:
    salt 'other_minion_id' mine.get 'netstat-master_id' eth0_ip_addrs

  • In your state files:
    {{ salt['mine.get']('netstat-master_id', 'eth0_ip_addrs') }}

In your case you can put it in the top of your Jinja template file.
{% set netdatamaster = salt['mine.get']('netstat-master_id', 'eth0_ip_addrs') %}

Upvotes: 1

Related Questions