I have a hacky solution, so hopefully someone else can find a better answer.
The approach is to create a Python script that runs salt
to grab the YAML output of network.ip_addrs eth0
then use that to call a particular sls with a pillar.
I made an example prototype which still needs to be implemented and tweaked:
#!/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 execute something along the lines of:
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 to nicely ask salt-minion to communicate to the master to run db.configure
on other nodes. I could simply execute the command similar to the script above.