Handle lists correctly in grains.list_prsesent

Closes #23548
This commit is contained in:
Mike Place 2015-05-13 11:31:07 -06:00
parent f20c0e42ce
commit da8a2f5cb3
2 changed files with 23 additions and 10 deletions

View File

@ -297,6 +297,10 @@ 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)
if isinstance(val, list):
for item in val:
grains.append(item)
else:
grains.append(val)
while delimiter in key:

View File

@ -103,7 +103,11 @@ def list_present(name, value):
ret['result'] = False
ret['comment'] = 'Grain {0} is not a valid list'.format(name)
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
@ -118,8 +122,13 @@ 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 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)