I'm using salt-cloud to deploy VMs and I'm trying to get them registred in my DNS with the Saltstack Reactor system.
I have a reactor.conf with this trigger:
reactor:
- 'salt/cloud/*/created': # Add a VM
- /srv/reactor/initialize_vm.sls
initilize_vm.sls :
invoke_orchestrate_add_to_dns:
runner.state.orchestrate:
- mods: orch.add_to_dns
- pillar:
event_name: {{ name }}
event_profile: {{ profile }}
orch/add_to_dns.sls:
{% set name = pillar['event_name'] %}
{% set profile = pillar['event_profile'] %}
vm-add-dns-{{ name }}:
sqlite3.row_present:
- db: /var/lib/powerdns/pdns.sqlite3
- table: records
- where_sql: "name='{{ name }}' and type='A'"
- data:
domain_id: 1
name: {{ name }}
type: A
content: {{ ??? }}
ttl: 300
prio: 0
disabled: 0
I just need to know the IP address of the new minion. But as the orchestration run on the master, I can't just do a content: {{ grains['fqdn_ip4'] }}.
Any ideas to get minions informations ?
You can use the Salt Mine to get information from minions. To use the Salt Mine you need to know which minion you want to have information from. Luckily the reactor receives the data from the event bus.
data['id']
contains the minion ID.In the Salt Mine you can add a function to retrieve a minions IP like this:
Now you can use
mine.get
in your sls files to get the IP address from a minion. In your case it will be the minion ID you just received from the event bus like this:Notes:
public_ip4
instead offqdn_ip4
. It's toclarify that this is a name in the Salt Mine and not the Grain you
are requesting.