2015-03-31 20:37:07 +00:00
|
|
|
#!/usr/bin/python
|
|
|
|
|
|
|
|
# Copyright (c) 2015 Hewlett-Packard Development Company, L.P.
|
2017-10-09 16:56:26 +00:00
|
|
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
|
|
|
|
|
|
from __future__ import absolute_import, division, print_function
|
|
|
|
__metaclass__ = type
|
|
|
|
|
2015-03-31 20:37:07 +00:00
|
|
|
|
2017-08-16 03:16:38 +00:00
|
|
|
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
2017-03-14 16:07:22 +00:00
|
|
|
'status': ['preview'],
|
|
|
|
'supported_by': 'community'}
|
|
|
|
|
2016-12-06 10:35:05 +00:00
|
|
|
|
2015-03-31 20:37:07 +00:00
|
|
|
DOCUMENTATION = '''
|
|
|
|
---
|
|
|
|
module: os_auth
|
|
|
|
short_description: Retrieve an auth token
|
2015-04-03 01:07:41 +00:00
|
|
|
version_added: "2.0"
|
2015-06-15 18:41:22 +00:00
|
|
|
author: "Monty Taylor (@emonty)"
|
2015-03-31 20:37:07 +00:00
|
|
|
description:
|
2016-12-08 14:38:05 +00:00
|
|
|
- Retrieve an auth token from an OpenStack Cloud
|
2016-12-08 02:33:38 +00:00
|
|
|
requirements:
|
2018-05-29 12:51:58 +00:00
|
|
|
- "python >= 2.7"
|
2018-05-26 01:40:39 +00:00
|
|
|
- "openstacksdk"
|
2017-02-17 20:49:03 +00:00
|
|
|
options:
|
|
|
|
availability_zone:
|
|
|
|
description:
|
2017-06-12 06:55:19 +00:00
|
|
|
- Ignored. Present for backwards compatibility
|
2017-02-17 20:49:03 +00:00
|
|
|
required: false
|
2015-04-03 01:07:41 +00:00
|
|
|
extends_documentation_fragment: openstack
|
2015-03-31 20:37:07 +00:00
|
|
|
'''
|
|
|
|
|
|
|
|
EXAMPLES = '''
|
2016-11-16 17:24:21 +00:00
|
|
|
- name: Authenticate to the cloud and retrieve the service catalog
|
|
|
|
os_auth:
|
2015-03-31 20:37:07 +00:00
|
|
|
cloud: rax-dfw
|
2016-11-16 17:24:21 +00:00
|
|
|
|
|
|
|
- name: Show service catalog
|
|
|
|
debug:
|
|
|
|
var: service_catalog
|
2015-03-31 20:37:07 +00:00
|
|
|
'''
|
|
|
|
|
2019-01-24 04:55:07 +00:00
|
|
|
RETURN = '''
|
|
|
|
auth_token:
|
|
|
|
description: Openstack API Auth Token
|
|
|
|
returned: success
|
|
|
|
type: str
|
|
|
|
service_catalog:
|
|
|
|
description: A dictionary of available API endpoints
|
|
|
|
returned: success
|
|
|
|
type: dict
|
|
|
|
'''
|
|
|
|
|
2017-10-09 16:56:26 +00:00
|
|
|
import traceback
|
|
|
|
|
|
|
|
from ansible.module_utils.basic import AnsibleModule
|
2018-02-15 14:20:49 +00:00
|
|
|
from ansible.module_utils.openstack import openstack_full_argument_spec, openstack_module_kwargs, openstack_cloud_from_module
|
2017-10-09 16:56:26 +00:00
|
|
|
|
2017-02-02 19:45:22 +00:00
|
|
|
|
2015-03-31 20:37:07 +00:00
|
|
|
def main():
|
|
|
|
|
|
|
|
argument_spec = openstack_full_argument_spec()
|
|
|
|
module_kwargs = openstack_module_kwargs()
|
|
|
|
module = AnsibleModule(argument_spec, **module_kwargs)
|
|
|
|
|
2018-05-26 01:40:39 +00:00
|
|
|
sdk, cloud = openstack_cloud_from_module(module)
|
2015-03-31 20:37:07 +00:00
|
|
|
try:
|
|
|
|
module.exit_json(
|
|
|
|
changed=False,
|
|
|
|
ansible_facts=dict(
|
2017-01-29 07:28:53 +00:00
|
|
|
auth_token=cloud.auth_token,
|
|
|
|
service_catalog=cloud.service_catalog))
|
2017-02-23 11:04:43 +00:00
|
|
|
except Exception as e:
|
|
|
|
module.fail_json(msg=str(e), exception=traceback.format_exc())
|
2015-03-31 20:37:07 +00:00
|
|
|
|
2017-10-09 16:56:26 +00:00
|
|
|
|
2016-12-08 02:33:38 +00:00
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|