Search code examples
pythonsalt-project

Insert list of tuple in Saltstack


I'm trying to pass a Python list of tuples ( ex : [(1, '1€'), (5, '5€')] ) in my init.sls It's a config file for my Django web server, and the config at some point need to retrieve this list of tuple from this file.

I tried the followings :

amount_choices: [(1, '1€'), (5, '5€')]

amount_choices:
- !!python/tuple : [1, '1€']

amount_choices: {% set amount_choice = (1, '1€') %} 

None of them worked as intended, at best the value is None whith the last proposition.

How can I insert my list of tuples into a sls file that uses the Jinja2 templates ?

Thank you very much


Solution

  • Back here to post the solution :

    in init.sls :

    amount_choices:
      "5 euros": 5
      "10 euros": 10
      "25 euros": 25
      "Montant libre": 0
    

    in the settings_local.py built by saltstack :

    AMOUNT_CHOICES = [
        {% for key, value in amount_choices.items() -%}
        ( {{ value }}, "{{ key }}" ),
        {% endfor -%}
        ]
    

    By constructing a dict and artificially recreating a tuple, we managed to get our way. Maybe better solutions are available, but I'm leaving this if anyone has the same problem someday.