mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 17:09:03 +00:00
parent
f20c0e42ce
commit
da8a2f5cb3
@ -297,7 +297,11 @@ def append(key, val, convert=False, delimiter=':'):
|
||||
return 'The key {0} is not a valid list'.format(key)
|
||||
if val in grains:
|
||||
return 'The val {0} was already in the list {1}'.format(val, key)
|
||||
grains.append(val)
|
||||
if isinstance(val, list):
|
||||
for item in val:
|
||||
grains.append(item)
|
||||
else:
|
||||
grains.append(val)
|
||||
|
||||
while delimiter in key:
|
||||
key, rest = key.rsplit(delimiter, 1)
|
||||
|
@ -103,10 +103,14 @@ def list_present(name, value):
|
||||
ret['result'] = False
|
||||
ret['comment'] = 'Grain {0} is not a valid list'.format(name)
|
||||
return ret
|
||||
|
||||
if value in grain:
|
||||
ret['comment'] = 'Value {1} is already in grain {0}'.format(name, value)
|
||||
return ret
|
||||
if isinstance(value, list):
|
||||
if set(value).issubset(set(__grains__.get(name))):
|
||||
ret['comment'] = 'Value {1} is already in grain {0}'.format(name, value)
|
||||
return ret
|
||||
else:
|
||||
if value in grain:
|
||||
ret['comment'] = 'Value {1} is already in grain {0}'.format(name, value)
|
||||
return ret
|
||||
if __opts__['test']:
|
||||
ret['result'] = None
|
||||
ret['comment'] = 'Value {1} is set to be appended to grain {0}'.format(name, value)
|
||||
@ -118,12 +122,17 @@ def list_present(name, value):
|
||||
ret['comment'] = 'Grain {0} is set to be added'.format(name)
|
||||
ret['changes'] = {'new': grain}
|
||||
return ret
|
||||
|
||||
new_grains = __salt__['grains.append'](name, value)
|
||||
if value not in __grains__.get(name):
|
||||
ret['result'] = False
|
||||
ret['comment'] = 'Failed append value {1} to grain {0}'.format(name, value)
|
||||
return ret
|
||||
if isinstance(value, list):
|
||||
if not set(value).issubset(set(__grains__.get(name))):
|
||||
ret['result'] = False
|
||||
ret['comment'] = 'Failed append value {1} to grain {0}'.format(name, value)
|
||||
return ret
|
||||
else:
|
||||
if value not in __grains__.get(name):
|
||||
ret['result'] = False
|
||||
ret['comment'] = 'Failed append value {1} to grain {0}'.format(name, value)
|
||||
return ret
|
||||
ret['comment'] = 'Append value {1} to grain {0}'.format(name, value)
|
||||
ret['changes'] = {'new': new_grains}
|
||||
return ret
|
||||
|
Loading…
Reference in New Issue
Block a user