|
20 | 20 | __metaclass__ = type |
21 | 21 |
|
22 | 22 | DOCUMENTATION = """ |
23 | | - name: combine_onto |
24 | | - author: Webster Mudge (@wmudge) <wmudge@cloudera.com> |
25 | | - short_description: combine two dictionaries |
26 | | - description: |
27 | | - - Create a dictionary (hash/associative array) as a result of merging existing dictionaries. |
28 | | - - This is the reverse of the C(ansible.builtin.combine) filter. |
29 | | - positional: _input, _dicts |
30 | | - options: |
31 | | - _input: |
32 | | - description: |
33 | | - - First dictionary to combine. |
34 | | - type: dict |
35 | | - required: True |
36 | | - _dicts: |
37 | | - description: |
38 | | - - The list of dictionaries to combine |
39 | | - type: list |
40 | | - elements: dict |
41 | | - required: True |
42 | | - recursive: |
43 | | - description: |
44 | | - - If V(True), merge elements recursively. |
45 | | - type: boolean |
46 | | - default: False |
47 | | - list_merge: |
48 | | - description: Behavior when encountering list elements. |
49 | | - type: str |
50 | | - default: replace |
51 | | - choices: |
52 | | - replace: overwrite older entries with newer ones |
53 | | - keep: discard newer entries |
54 | | - append: append newer entries to the older ones |
55 | | - prepend: insert newer entries in front of the older ones |
56 | | - append_rp: append newer entries to the older ones, overwrite duplicates |
57 | | - prepend_rp: insert newer entries in front of the older ones, discard duplicates |
| 23 | +name: combine_onto |
| 24 | +author: Webster Mudge (@wmudge) <wmudge@cloudera.com> |
| 25 | +short_description: combine two dictionaries |
| 26 | +description: |
| 27 | + - Create a dictionary (hash/associative array) as a result of merging existing dictionaries. |
| 28 | + - This is the reverse of the C(ansible.builtin.combine) filter. |
| 29 | +positional: _input, _dicts |
| 30 | +options: |
| 31 | + _input: |
| 32 | + description: |
| 33 | + - First dictionary to combine. |
| 34 | + type: dict |
| 35 | + required: True |
| 36 | + _dicts: |
| 37 | + description: |
| 38 | + - The list of dictionaries to combine |
| 39 | + type: list |
| 40 | + elements: dict |
| 41 | + required: True |
| 42 | + recursive: |
| 43 | + description: |
| 44 | + - If V(True), merge elements recursively. |
| 45 | + type: boolean |
| 46 | + default: False |
| 47 | + list_merge: |
| 48 | + description: Behavior when encountering list elements. |
| 49 | + type: str |
| 50 | + default: replace |
| 51 | + choices: |
| 52 | + replace: overwrite older entries with newer ones |
| 53 | + keep: discard newer entries |
| 54 | + append: append newer entries to the older ones |
| 55 | + prepend: insert newer entries in front of the older ones |
| 56 | + append_rp: append newer entries to the older ones, overwrite duplicates |
| 57 | + prepend_rp: insert newer entries in front of the older ones, discard duplicates |
58 | 58 | """ |
59 | 59 |
|
60 | 60 | EXAMPLES = """ |
61 | | - # ab => {'a':1, 'b':2, 'c': 4} |
62 | | - ab: "{{ {'a':1, 'b':2} | cloudera.exe.combine_onto({'b':3, 'c':4}) }}" |
| 61 | +# ab => {'a':1, 'b':2, 'c': 4} |
| 62 | +ab: "{{ {'a':1, 'b':2} | cloudera.exe.combine_onto({'b':3, 'c':4}) }}" |
63 | 63 |
|
64 | | - many: "{{ dict1 | cloudera.exe.combine_onto(dict2, dict3, dict4) }}" |
| 64 | +many: "{{ dict1 | cloudera.exe.combine_onto(dict2, dict3, dict4) }}" |
65 | 65 |
|
66 | | - # defaults => {'a':{'b':3, 'c':4}, 'd': 5} |
67 | | - # customization => {'a':{'c':20}} |
68 | | - # final => {'a':{'b':3, 'c':20}, 'd': 5} |
69 | | - final: "{{ customization | cloudera.exe.combine_onto(defaults, recursive=true) }}" |
| 66 | +# defaults => {'a':{'b':3, 'c':4}, 'd': 5} |
| 67 | +# customization => {'a':{'c':20}} |
| 68 | +# final => {'a':{'b':3, 'c':20}, 'd': 5} |
| 69 | +final: "{{ customization | cloudera.exe.combine_onto(defaults, recursive=true) }}" |
70 | 70 | """ |
71 | 71 |
|
72 | 72 | RETURN = """ |
73 | | - _value: |
74 | | - description: Resulting merge of supplied dictionaries. |
75 | | - type: dict |
| 73 | +_value: |
| 74 | + description: Resulting merge of supplied dictionaries. |
| 75 | + type: dict |
76 | 76 | """ |
77 | 77 |
|
78 | 78 | from ansible.errors import AnsibleFilterError |
|
0 commit comments