From 0283791d5f1bb4354024c5f873690bdea219aec8 Mon Sep 17 00:00:00 2001 From: Monty Taylor Date: Tue, 31 Mar 2015 16:37:07 -0400 Subject: [PATCH] Add OpenStack Auth module Use this to pre-auth or to get a copy of the service catalog. --- .../modules/cloud/openstack/os_auth.py | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 lib/ansible/modules/cloud/openstack/os_auth.py diff --git a/lib/ansible/modules/cloud/openstack/os_auth.py b/lib/ansible/modules/cloud/openstack/os_auth.py new file mode 100644 index 00000000000..848c2861c84 --- /dev/null +++ b/lib/ansible/modules/cloud/openstack/os_auth.py @@ -0,0 +1,66 @@ +#!/usr/bin/python + +# Copyright (c) 2015 Hewlett-Packard Development Company, L.P. +# +# This module is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This software is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this software. If not, see . + +try: + import shade + from shade import meta + HAS_SHADE = True +except ImportError: + HAS_SHADE = False + +DOCUMENTATION = ''' +--- +module: os_auth +short_description: Retrieve an auth token +version_added: "1.10" +extends_documentation_fragment: openstack +description: + - Retrieve an auth token from an OpenStack Cloud +options: +requirements: ["shade"] +''' + +EXAMPLES = ''' +# Authenticate to the cloud and retreive the service catalog +- os_auth: + cloud: rax-dfw +- debug: var=service_catalog +''' + +def main(): + + argument_spec = openstack_full_argument_spec() + module_kwargs = openstack_module_kwargs() + module = AnsibleModule(argument_spec, **module_kwargs) + + if not HAS_SHADE: + module.fail_json(msg='shade is required for this module') + + try: + cloud = shade.openstack_cloud(**module.params) + module.exit_json( + changed=False, + ansible_facts=dict( + auth_token=cloud.auth_token, + service_catalog=cloud.service_catalog)) + except shade.OpenStackCloudException as e: + module.fail_json(msg=e.message) + +# this is magic, see lib/ansible/module_common.py +from ansible.module_utils.basic import * +from ansible.module_utils.openstack import * +main()