kwakhed
kwakhed

Reputation: 89

Salt-key command in runner

I'm writing a custom Salt Stack runner to wrap accepting and rejecting minions. How do I call salt-key from my python runner that's equivalent to this from command line

salt-key -a {minion_name}

Upvotes: 2

Views: 1199

Answers (2)

Alp
Alp

Reputation: 3105

I know it has been a while since this question is answered, I would like to add my two cents on this subject.

In order to do key interactions programmatically, we use Wheel in salt. Usage is rather simple and clear:

from salt import config
from salt import wheel
masterOpts = config.master_config('/etc/salt/master')
wheelClient = wheel.WheelClient(masterOpts)
wheelClient.cmd('key.accept', ['minionId1'])

Bunch of other operations could be found in SaltStack documentatation here

Upvotes: 1

memoselyk
memoselyk

Reputation: 4118

I can't provide you a definite answer, but here are my two cents:

The source code of the salt-key script is this one. Following the call chain, I reached this module which contains several classes to do key processing.

The module's documentation reads:

The Salt Key backend API and interface used by the CLI. The Key class can be used to manage salt keys directly without interfacing with the CLI.

This is the mentioned class.

Based on this code, I presume it's used like:

import salt.client
import salt.key

client = salt.client.LocalClient()
key_manager = salt.key.Key(client.opts)
key_manager.accept('web*')

Upvotes: 4

Related Questions