Created
August 26, 2015 17:38
-
-
Save joedougherty/afac25b28f5282560e84 to your computer and use it in GitHub Desktop.
Convert bash script into Python for cross-platform running
This file contains hidden or 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
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