sap.sap_operations.combine_default (1.25.0) — filter

Combine two dictionaries, second dictionary will be used as default.

| "added in version" 1.11.0 of sap.sap_operations"

Authors: Kirill Satarin (@kksat)

Install collection

Install with ansible-galaxy collection install sap.sap_operations:==1.25.0


Add to requirements.yml

  collections:
    - name: sap.sap_operations
      version: 1.25.0

Description

Combine two dictionaries, second dictionary will be used as default.

If key is present in both dictionaries, value from first dictionary (not value from default) will be used.

If value is not dictionary, it will be returned as is.

If value is None, default will be returned.

This is expected to work only with one level of nesting for dictionaries.

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Test filter `combine_default`, this assertion is True
  ansible.builtin.assert:
    that:
      - ( 'ABC' | sap.sap_operations.combine_default('DEF') ) == 'ABC'
      - ( 123 | sap.sap_operations.combine_default('DEF') ) == 123
      - ( [1, 2, 3] | sap.sap_operations.combine_default('DEF') ) == [1, 2, 3]
      - ( {"key":"value"} | sap.sap_operations.combine_default('DEF') ) == {"key":"value"}
      - True | sap.sap_operations.combine_default('DEF') == True
      - False | sap.sap_operations.combine_default('DEF') == False
      - 0 | sap.sap_operations.combine_default('DEF') == 0
      - 1 | sap.sap_operations.combine_default('DEF') == 1
      - None | sap.sap_operations.combine_default('DEF') == 'DEF'
      - value | sap.sap_operations.combine_default(default) == result1
      - default | sap.sap_operations.combine_default(value) == result2
  vars:
    value:
      key1: value1
      key2: value2
    default:
      key2: new_value2
      key3: value3
    result1:
      key1: value1
      key2: value2
      key3: value3
    result2:
      key1: value1
      key2: new_value2
      key3: value3

Inputs

    
value:
    description: Dictionary to combine with default.
    required: true
    type: dict

default:
    description: Dictionary to use as default.
    required: false
    type: dict

Outputs

data:
  description:
  - Combined dictionary.
  - If key is present in both dictionaries, value from first dictionary (not value
    from default) will be used.
  - If value is not dictionary, it will be returned as is.
  - If value is None, default will be returned.
  type: dict