Created
March 28, 2018 13:41
-
-
Save danilochilene/2d12c89f04900e45669f44ae4f6a1c3a to your computer and use it in GitHub Desktop.
salt-run return as variable
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
root@saltserver:/srv/salt/tools# salt-run minion.token | |
minion01: | |
fa651fe9be09fcadfe0fcc6fc018ab21 | |
root@salt:/srv/salt/tools# salt 'minion01' state.sls tools/install-minion | |
minion01: | |
Data failed to compile: | |
---------- | |
Rendering SLS 'base:tools/install-minion' failed: Jinja error: 'minion.token' | |
Traceback (most recent call last): | |
File "/usr/lib/python2.7/dist-packages/salt/utils/templates.py", line 418, in render_jinja_tmpl | |
output = template.render(**decoded_context) | |
File "/usr/lib/python2.7/dist-packages/jinja2/environment.py", line 989, in render | |
return self.environment.handle_exception(exc_info, True) | |
File "/usr/lib/python2.7/dist-packages/jinja2/environment.py", line 754, in handle_exception | |
reraise(exc_type, exc_value, tb) | |
File "<template>", line 1, in top-level template code | |
File "/usr/lib/python2.7/dist-packages/salt/modules/saltutil.py", line 1444, in runner | |
full_return=full_return) | |
File "/usr/lib/python2.7/dist-packages/salt/runner.py", line 153, in cmd | |
full_return) | |
File "/usr/lib/python2.7/dist-packages/salt/client/mixins.py", line 228, in cmd | |
self.functions[fun], arglist, pub_data | |
File "/usr/lib/python2.7/dist-packages/salt/loader.py", line 1114, in __getitem__ | |
func = super(LazyLoader, self).__getitem__(item) | |
File "/usr/lib/python2.7/dist-packages/salt/utils/lazy.py", line 101, in __getitem__ | |
raise KeyError(key) | |
KeyError: 'minion.token' | |
; line 1 | |
--- | |
{% set token = salt['saltutil.runner']('minion.token') %} <====================== |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
salt-master
cluster01 = where cluster runs
minion01 = wants to join the cluster
the idea is to run a state to install the software required on minion01 and grab the token generated from cluster01 and pass to minion01. The token is sensitive data and has a TTL.