Skip to content

Instantly share code, notes, and snippets.

@thecodeassassin
Created September 4, 2013 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thecodeassassin/596997363f181a7db06d to your computer and use it in GitHub Desktop.
Save thecodeassassin/596997363f181a7db06d to your computer and use it in GitHub Desktop.
def add_role(target, role):
target_grains = client().cmd(target, 'grains.items')
for host, grains in target_grains.items():
roles = grains.get('roles', [])
if role not in roles:
roles.append(role)
result = client().cmd(
host, 'grains.setval', ['roles', json.dumps(roles)])
print result
else:
print {host: {'roles': roles}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment