Using the salt outlet to be used as a status input or SLS rack?
You can use Salt Mine to do this. First, distribute this configuration with all Minions:
mine_functions:
grains.item:
- roles
- fqdn_ip4
With this configuration, every Minion will publish these two seeds to all other minions. Read more about Mine here .
Now we can create a file with all names with role = db.
/tmp/mydbhosts:
file:
- managed
- source: salt://example/myhosts
- template: mako
Example template / myhosts:
% for minion, peer_grains in salt['mine.get']('*', 'grains.items').items():
% if "db" in peer_grains["role"]:
minion peer_grains["fqdn_ip4"]
% endif
% endfor
source to share
I have a hacky solution, so hopefully someone else finds a better answer.
The approach is to create a Python script that runs salt
to grab the YAML output network.ip_addrs eth0
, then use it to call specific sls using the column.
I made a rough prototype that still needs to be implemented and configured:
#!/usr/bin/env python
import subprocess
import yaml
# Query all db nodes for their ip addresses
data = subprocess.check_output(
'salt -G "role:db" network.ip_addrs eth0',
shell=True
)
data = yaml.load(data)
# Parse and reshuffle for pillar input
addrs = []
for a in data.values():
addrs.append(a[0])
addrs = yaml.dump({'db_peers': addrs})
# Update configuration file on each node
data = subprocess.check_output(
'salt -G "role:db" state.sls db.configure pillar="{}"'.format(addrs),
shell=True
)
This will do something along the lines:
salt -G "role:db" state.sls db.configure pillar="db_peers: [1.2.3.4, 2.3.4.5]"
This could potentially be put into a module, but I'm not sure how nice it is to ask a salty minion to contact the master to run db.configure
on other nodes. I could just execute a command similar to the script above.
source to share