mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-07 05:42:50 +00:00
Merge pull request #1903 from leucos/mergeable-hash-vars
Adds user-selectable hash merging support in vars
This commit is contained in:
@@ -19,6 +19,7 @@ import sys
|
||||
import os
|
||||
import shlex
|
||||
import yaml
|
||||
import copy
|
||||
import optparse
|
||||
import operator
|
||||
from ansible import errors
|
||||
@@ -273,6 +274,26 @@ def parse_kv(args):
|
||||
options[k]=v
|
||||
return options
|
||||
|
||||
def merge_hash(a, b):
|
||||
''' merges hash b into a
|
||||
this means that if b has key k, the resulting has will have a key k
|
||||
which value comes from b
|
||||
said differently, all key/value combination from b will override a's '''
|
||||
|
||||
# and iterate over b keys
|
||||
for k, v in b.iteritems():
|
||||
if k in a and isinstance(a[k], dict):
|
||||
# if this key is a hash and exists in a
|
||||
# we recursively call ourselves with
|
||||
# the key value of b
|
||||
a[k] = merge_hash(a[k], v)
|
||||
else:
|
||||
# k is not in a, no need to merge b, we just deecopy
|
||||
# or k is not a dictionnary, no need to merge b either, we just deecopy it
|
||||
a[k] = v
|
||||
# finally, return the resulting hash when we're done iterating keys
|
||||
return a
|
||||
|
||||
def md5s(data):
|
||||
''' Return MD5 hex digest of data. '''
|
||||
|
||||
|
||||
Reference in New Issue
Block a user