Skip to content

Instantly share code, notes, and snippets.

@ekohl
Created June 19, 2013 10:30
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 ekohl/5813331 to your computer and use it in GitHub Desktop.
Save ekohl/5813331 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import getpass
import requests
import sys
url = 'https://foreman/api'
verify = False
try:
username = sys.argv[1]
except IndexError:
username = getpass.getuser()
password = getpass.getpass()
auth = (username, password)
smart_proxy_name = 'my_proxy'
# Find the smart proxy ID
r = requests.get(url + '/smart_proxies', auth=auth, verify=False)
for smart_proxy in r.json():
if smart_proxy['smart_proxy']['name'] == smart_proxy_name:
put_params = {
'host[puppet_ca_proxy_id]': smart_proxy['smart_proxy']['id'],
'host[puppet_proxy_id]': smart_proxy['smart_proxy']['id'],
}
break
else:
print 'Could not find ' + smart_proxy_name
sys.exit(1)
search_params = {'search': 'not has puppetmaster', 'per_page': 400}
r = requests.get(url + '/hosts', params=search_params, auth=auth,
verify=verify)
for host in r.json():
requests.put('%s/hosts/%s' % (url, host['host']['id']), params=put_params,
auth=auth, verify=verify)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment