1

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

We structure our systems like this:

systems:
  - 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?

guettli
  • 3,113
  • 14
  • 59
  • 110

1 Answers1

1

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 }}:
  test.configurable_test_state:
    - 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.

Christophe Drevet
  • 1,962
  • 2
  • 17
  • 25
  • 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 08 '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 Feb 08 '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 08 '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 https://saltstack.com/community/ for links and information. – Christophe Drevet Feb 09 '16 at 07:41
  • I asked on the mailing list (related, but different topic). Here is the reply: https://groups.google.com/forum/#!topic/salt-users/5Oa48H1QYtk He suggested to use external pillars. See https://docs.saltstack.com/en/latest/topics/development/external_pillars.html – guettli Feb 09 '16 at 07:57