Dr.Knowitall
Dr.Knowitall

Reputation: 10478

How can I provision salt minion on connect

I have an AWS setup where I have a designated salt master that accepts all incoming keys and a provisions based on subnet/designated ip addresses. How can I immediately provision my minions on connect without logging into the master server to do so?

Upvotes: 3

Views: 2465

Answers (2)

Utah_Dave
Utah_Dave

Reputation: 4581

John Hazen's approach definitely works. There's also a somewhat simpler option you can enable: startup_states

If you have this set in the minion config, then a highstate will get run each time the minion starts up:

startup_states: highstate

https://docs.saltstack.com/en/latest/ref/states/startup.html

Upvotes: 3

John Hazen
John Hazen

Reputation: 1371

The way to do this is with the reactor system. Exactly how to do it depends on what you mean by "on connect". If you want a minion to highstate every time it connects, then you want to react to the event tag:

salt/minion/*/start

If you want to execute the highstate only when the minion connects for the first time (when its key is accepted), then you'll need to turn off auto-accept, and react to the

salt/auth

tag. (In this case, you'll need to accept the key, and then execute the highstate, after waiting for the minion to actually connect.) Since that's more complicated, I'll show you the first one. You should be able to extrapolate for the latter case.

First you need to tell the salt-master to react to the tag:

# File: /etc/salt/master.d/reactor.conf
reactor:
  - 'salt/minion/*/start':
    - /srv/reactor/highstate.sls

And then you need the highstate.sls file:

# File: /srv/reactor/highstate.sls
minion_highstate:
  local.state.highstate:
    - tgt: {{ data['id'] }}

After implementing this, I get this (with snippage) in my minion log:

2016-03-18 23:07:06,009 [salt.cli.daemons ][INFO    ][21627] Setting up the Salt Minion "jhazentest05.example.net"
2016-03-18 23:07:06,219 [salt.cli.daemons ][INFO    ][21627] The salt minion is starting up
2016-03-18 23:07:06,707 [salt.minion      ][INFO    ][21627] Minion is ready to receive requests!
2016-03-18 23:07:06,708 [salt.minion      ][INFO    ][21627] User root Executing command state.highstate with jid 20160318230706334642
2016-03-18 23:07:09,699 [salt.minion      ][INFO    ][21700] Returning information for job: 20160318230706334642

Upvotes: 6

Related Questions