Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to pass a dict as function argument in salt

I need to use a

pip.installed

function in salt and pass it an argument

env_vars

with multiple params which should be eventually rendered to a python dictionary. It is okay if there were one parameter and the argument was expecting an argument of the type other than dictionary i then could pass it like so:

pip.installed:
  - env_vars: my_var

But i need to pass a dict and im not sure how to do it.

Should it be a construct like:

pip.installed:
  - env_vars:
    - my_var1: var_value
    - my_var2: var_value2

And how should i checked that my config actually renders to the correct form?

like image 906
canufeel Avatar asked Dec 20 '25 21:12

canufeel


1 Answers

That answer is not correct, Salt will issue a warning.

pip.installed:
  - env_vars:
    my_var1: var_value
    my_var2: var_value2

Warnings: 'my_var2' and 'my_var1' are invalid keyword arguments for
          'pip.installed'. If you were trying to pass additional data to be
          used in a template context, please populate 'context' with 'key:
          value' pairs. Your approach will work until Salt Carbon is out.
          Please update your state files.

The variables need to be nested another level deep like this:

pip.installed:
  - env_vars:
      my_var1: var_value
      my_var2: var_value2
like image 73
Damian Avatar answered Dec 23 '25 03:12

Damian



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!