How do I pass parameters to a salt state file?

Ryan Currah picture Ryan Currah · Sep 21, 2014 · Viewed 10.6k times · Source

I want to create a group and user using salt state files, but I do not know the group, gid, user, uid, sshkey until I need to execute the salt state file which I would like to pass in as parameters.

I have read about Pillar to create the variable. How do I create pillars before execution?

/srv/salt/group.sls:

{{ name }}:
  group.present:
    - gid: {{ gid }}
    - system: True

Command line:

salt 'SaltStack-01' state.sls group name=awesome gid=123456

Answer

Utah_Dave picture Utah_Dave · Jul 12, 2017

If you really want to pass in the data on the command like you can also do it like this:

{{ pillar['name'] }}:
  group.present:
    - gid: {{ pillar['gid'] }}
    - system: True

Then on the command line you can pass in the data like this:

salt 'SaltStack-01' state.sls group pillar='{"name": "awesome", "gid": "123456"}'