Skip to content

Conversation

@aabouzaid
Copy link
Contributor

What does this PR do?

Add defaults.update function.

What issues does this PR fix or reference?

After enhancing defaults module with PR no. #44851 and #44850

I found that we have a lot of redundant in jinja, so this function is a combination of defaults.merge and defaults.deepcopy to avoid redundancy.

Here is an arbitrary example:

Yaml

group01:
  defaults:
    enabled: True
    extra:
      - test
      - stage
  nodes:
    host01:
      index: foo
      upstream: bar
    host02:
      index: foo2
      upstream: bar2

Expected output of group01.nodes.host01:

host01:
  index: foo
  upstream: bar
  enabled: True
  aggregate: source
  extra:
    - test
    - stage

Old style that done with Jinja:

{% for host, vars in group01.nodes.items() %}
  {% set defaults = salt['defaults.deepcopy'](group01.defaults) %}
  {% set host_vars = salt['defaults.merge'](defaults, vars) %}
  ....
{% endfor %}

The same thing with the new function defaults.update:

{% do salt['defaults.update'](group01.nodes, group01.defaults) %}

New Behavior

Better merge of defaults for groups.

Tests written?

Yes

Commits signed with GPG?

Yes

@rallytime rallytime merged commit dafb42f into saltstack:develop Dec 22, 2017
@aabouzaid
Copy link
Contributor Author

@rallytime It's almost a year, when this function will be available please? 🤔

@rallytime
Copy link
Contributor

It will be available in Fluorine.

@aabouzaid
Copy link
Contributor Author

Ah, ok 👍
Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants