Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add defaults.update function. #45051

Merged
merged 2 commits into from Dec 22, 2017
Merged

Conversation

@aabouzaid
Copy link
Contributor

@aabouzaid aabouzaid commented Dec 16, 2017

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
6 of 9 checks passed
@aabouzaid
Copy link
Contributor Author

@aabouzaid aabouzaid commented Nov 26, 2018

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

@rallytime
Copy link
Contributor

@rallytime rallytime commented Nov 28, 2018

It will be available in Fluorine.

@aabouzaid
Copy link
Contributor Author

@aabouzaid aabouzaid commented Nov 29, 2018

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
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants