I would like to have properties (computed attributes) for data from saltstack pillars:

We structure our systems like this:

  - customer: foo 
    project: bar
    stage: p
  - customer: foo
    project: bar
    stage: q

I would like to compute a variable "system.name" like this: "{customer}_{project}_{stage}".

From the above example I would get these two computes values:

  • system.name = "foo_bar_p"
  • system.name = "foo_bar_q"

I would be able to access system.name just like system.customer or system.project.

How to get this done?


I don't think you can define properties like you'd like.

However, you can compute this value inside your state file or your template with jinja commands. For example:

{% for system in salt['pillar.get']('systems', []) %}
  {% do system.update({'name': system.customer + '_' + system.project + '_' + system.stage}) %}
test_state_for_{{ system.name }}:
    - result: False
    - comment: {{ system }}
{% endfor %}

In this example, the system dict is updated (merged) with the name computed value: system.customer + '_' + system.project + '_' + system.stage.

  • 1
    Yes, your solution should work. Thank you. Still, somehow a solution which looks nicer would be better. I personally like object oriented programming: Properties and inheritance are great and the result looks readable. – guettli Feb 8 '16 at 12:50
  • SaltStack is always evolving and something could be proposed. They are very open to suggestions and, even more, to pull requests. – Christophe Drevet-Droguet Feb 8 '16 at 14:40
  • @ChristopheDrevetDroguet I can not create a pull request, since my current idea is still vague. What is the best place for talking to the developers? After defining "done" I can start to code :-) – guettli Feb 8 '16 at 14:44
  • Well, you can open an issue on github, and discuss it here (sometimes it's more of a monologue but it's public, at least). Or to the "users" mailling list or the IRC chat. See saltstack.com/community for links and information. – Christophe Drevet-Droguet Feb 9 '16 at 7:41
  • I asked on the mailing list (related, but different topic). Here is the reply: groups.google.com/forum/#!topic/salt-users/5Oa48H1QYtk He suggested to use external pillars. See docs.saltstack.com/en/latest/topics/development/… – guettli Feb 9 '16 at 7:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.