Created
January 13, 2015 00:21
-
-
Save yuuichi-fujioka/c51757b6ae397ed0467a to your computer and use it in GitHub Desktop.
generate ansible inventory from openstack.
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
#!/usr/bin/env python | |
import os | |
from novaclient import client as nclient | |
def get_nova_client(): | |
auth_url = os.environ['OS_AUTH_URL'] | |
tenant = os.environ['OS_TENANT_NAME'] | |
username = os.environ['OS_USERNAME'] | |
password = os.environ['OS_PASSWORD'] | |
return nclient.Client('2', username=username, api_key=password, project_id=tenant, auth_url=auth_url) | |
def main(args): | |
no = get_nova_client() | |
servers = no.servers.list() | |
for s in servers: | |
for net, address in s.addresses.items(): | |
for a in address: | |
print s.name + "." + net + " ansible_ssh_host=" + a['addr'] + " ansible_ssh_user=ubuntu" | |
if __name__ == '__main__': | |
import sys | |
main(sys.argv[1:]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment