Passing variables from command line

2,401 views
Skip to first unread message

ig...@xorops.com

unread,
Apr 12, 2013, 7:54:13 AM4/12/13
to salt-...@googlegroups.com
How can I pass variables to module from command line?

I tried like this:

salt target state.sls module var1=value

and then in module use it like {{ var1 }} but it doesn't work.

Thanks.

Regards,
Igor

Erik Johnson

unread,
Apr 12, 2013, 11:58:12 AM4/12/13
to salt-...@googlegroups.com
To my knowledge this is not possible. Also, just to get the terminology clear, the "module" you are referring to is not a module, it's an SLS file.


--

-Erik

"For me, it is far better to grasp the universe as it really is than to persist in delusion, however satisfying and reassuring."  -- Carl Sagan

Paul Traylor

unread,
Apr 12, 2013, 12:20:41 PM4/12/13
to salt-...@googlegroups.com
2013/4/12 Erik Johnson <pale...@gmail.com>:
> On Fri, Apr 12, 2013 at 6:54 AM, <ig...@xorops.com> wrote:
>
>> How can I pass variables to module from command line?
>>
>> I tried like this:
>>
>> salt target state.sls module var1=value
>>
>> and then in module use it like {{ var1 }} but it doesn't work.
>>
>> Thanks.
>>
>> Regards,
>> Igor
>>
>
> To my knowledge this is not possible. Also, just to get the terminology
> clear, the "module" you are referring to is not a module, it's an SLS file.
> -Erik

https://salt.readthedocs.org/en/latest/topics/releases/0.13.0.html
You could specify an extra pillar value from the CLI

salt * state.highstate pillar='{"cheese": "spam"}'

Depending on how you have structured your sls files and pillar values
that could work.


--
Paul Traylor
https://github.com/kfdm

Erik Johnson

unread,
Apr 12, 2013, 3:36:11 PM4/12/13
to salt-...@googlegroups.com
On Fri, Apr 12, 2013 at 11:20 AM, Paul Traylor <kungfudi...@gmail.com> wrote:
https://salt.readthedocs.org/en/latest/topics/releases/0.13.0.html
You could specify an extra pillar value from the CLI

salt * state.highstate pillar='{"cheese": "spam"}'

Depending on how you have structured your sls files and pillar values
that could work.


--
Paul Traylor
https://github.com/kfdm

--
You received this message because you are subscribed to the Google Groups "Salt-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to salt-users+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Holy crap, that's awesome. I regularly write code for Salt and I did not know this. Thanks!

ig...@xorops.com

unread,
Apr 15, 2013, 2:22:46 AM4/15/13
to salt-...@googlegroups.com
Thanks, can I use this with state.sls?
If another command is triggered at the same time will it have ability to overwrite values of other?
Is this only in-memory for duration of that command or is stored somewhere?

On Friday, April 12, 2013 6:20:41 PM UTC+2, KFDM wrote:
2013/4/12 Erik Johnson <pale...@gmail.com>:

ig...@xorops.com

unread,
Apr 16, 2013, 1:58:28 AM4/16/13
to salt-...@googlegroups.com
This simple PoC is working, if anybody requires this. 

salt host1 state.sls state1 pillar='{"nics": ["eth0", "eth1", "eth2"]}'

{% for nic in pillar['nics'] %}

{{ nic }}:
  module.run:
  - name: network.hwaddr
  - iface: {{ nic }}
{% endfor %}

ashish...@opcito.com

unread,
Apr 27, 2016, 12:00:18 AM4/27/16
to Salt-users
Hi,

I tried passing the variables on salt version "salt 2015.8.8.2 (Beryllium)" but the command fails to execute.
Is there a change in the way this is done in latest release ?

This is how I tried, which didn't work::

sudo salt 'test-server-1' state.sls server-1 pillar='{"host1": "server-1.example.com"}' -l debug

And here is the output of the command::

[DEBUG   ] Reading configuration from /etc/salt/master
[DEBUG   ] Using cached minion ID from /etc/salt/minion_id: salt
[DEBUG   ] Key 'file_ignore_glob' with value None has an invalid type of NoneType, a list is required for this value
[DEBUG   ] Missing configuration file: /home/ubuntu/.saltrc
[DEBUG   ] Key 'file_ignore_glob' with value None has an invalid type of NoneType, a list is required for this value
[DEBUG   ] Configuration file path: /etc/salt/master
[WARNING ] Insecure logging configuration detected! Sensitive data may be logged.
[DEBUG   ] Reading configuration from /etc/salt/master
[DEBUG   ] Using cached minion ID from /etc/salt/minion_id: salt
[DEBUG   ] Key 'file_ignore_glob' with value None has an invalid type of NoneType, a list is required for this value
[DEBUG   ] Missing configuration file: /home/ubuntu/.saltrc
[DEBUG   ] Key 'file_ignore_glob' with value None has an invalid type of NoneType, a list is required for this value
[DEBUG   ] MasterEvent PUB socket URI: ipc:///var/run/salt/master/master_event_pub.ipc
[DEBUG   ] MasterEvent PULL socket URI: ipc:///var/run/salt/master/master_event_pull.ipc
[DEBUG   ] Initializing new AsyncZeroMQReqChannel for ('/etc/salt/pki/master', 'salt_master', 'tcp://127.0.0.1:4506', 'clear')
No minions matched the target. No command was sent, no jid was assigned.
[DEBUG   ] LazyLoaded nested.output
ERROR: No return received


Please help me solve this.

Thanks in advance.

Regards,
apapap

Colton Myers

unread,
Apr 27, 2016, 11:34:00 AM4/27/16
to salt-...@googlegroups.com
Your syntax looks correct. You might be running into a different issue. Does the command work without sending in the custom pillar?

--
Colton Myers
@basepi

--
You received this message because you are subscribed to the Google Groups "Salt-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to salt-users+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Shane Lee

unread,
Apr 27, 2016, 2:26:44 PM4/27/16
to Salt-users
Are you referencing the pillar data in your state file?
Reply all
Reply to author
Forward
0 new messages