Skip to content

Instantly share code, notes, and snippets.

@joedougherty
Created August 26, 2015 17:38
Show Gist options
  • Save joedougherty/afac25b28f5282560e84 to your computer and use it in GitHub Desktop.
Save joedougherty/afac25b28f5282560e84 to your computer and use it in GitHub Desktop.
Convert bash script into Python for cross-platform running
import tempfile, os, subprocess
if not 'DO_API_TOKEN' in os.environ:
print("DigitalOcean API token not found. Export DO_API_TOKEN.")
exit(1)
with tempfile.NamedTemporaryFile() as fp:
fp.write("localhost ansible_connection=local")
invocation = "ansible localhost -i {tmpfile} -m digital_ocean -a".format(tmpfile=fp.name).split(' ')
invocation.append('command=ssh list_keys=true')
subprocess.call(invocation)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment