Created
June 19, 2013 10:30
-
-
Save ekohl/5813331 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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