Skip to content

Instantly share code, notes, and snippets.

@LeeBrown
Last active December 27, 2015 23:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LeeBrown/7403445 to your computer and use it in GitHub Desktop.
Save LeeBrown/7403445 to your computer and use it in GitHub Desktop.
example call: salt -l debug -v NetMon_Sonoma state.sls ssh-keys.generate-host-key. generate-host-key is executed on NetMon_Sonoma. NetMon_Sonoma fires an event on the master. Master executes the sync-shared-keys.sls with data['data']['foo'] equal to 'mMaster', filters correctly How do I pass information to the fetch-host-keys when I execute the …
# salt -l debug -v NetMon_Sonoma state.sls ssh-keys.generate-host-key.
generate-host-key is executed on NetMon_Sonoma.
NetMon_Sonoma fires an event on the master.
Master executes the sync-shared-keys.sls with data['data']['foo'] equal to 'mMaster'. the ssh-keys/fetch-host-keys.sls is executed on the mMaster minion.
How do I pass information to the fetch-host-keys when I execute the sls?
Is this what kwargs is used for?
remove_known_host:
module.run:
- name: ssh.rm_known_host
- {{ kwargs['something'] }}
How do I get this data ^^^^^^^^
/etc/ssh/ssh_host_rsa_key:
file.absent
update_ssh_host_rsa_key:
cmd.run:
- name: "/usr/bin/ssh-keygen -t rsa -b 2048 -N \"\" -q -f /etc/ssh/ssh_host_rsa_key"
- cwd: /root
update_ssh_host_rsa_key.pub:
module.run:
- name: "event.fire_master"
- fun: fire_master
- tag: RefreshHostSSHPub
- data: {"foo": "mMaster"}
### The data foo is usable in the reactor's sync-shared-keys.sls. We use it to build the targeting filter
reactor:
- 'RefreshHostSSHPub':
- /usr/local/etc/salt/states/ssh-keys/reactor/sync-shared-keys.sls
anything:
cmd.state.sls:
- tgt: 'G@Notify_{{ data['id'] }}_{{ data['tag'] }}:True and L@{{ data['data']['foo'] }}'
- expr_form: compound
- arg:
- ssh-keys.fetch-host-keys
- kwargs:
- something: else
@whiteinge
Copy link

Unfortunately the kwargs parameter is not used for what you're trying to do. However there is a keyword argument that will work for what your'e doing: pillar.

At the CLI you can do something like:

salt 'mytarget' state.sls mysls pillar='{foo: bar}'

And access that Pillar data in "mysls.sls" via the usual way:

mycmd:
  cmd:
    - run
    - name: echo {{ salt['pillar.get']('foo') }}

So if you change the kwargs in your sync-shared-keys.sls to pillar it should work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment