mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Add OpenStack Auth module
Use this to pre-auth or to get a copy of the service catalog.
This commit is contained in:
parent
9d93f052c2
commit
0283791d5f
1 changed files with 66 additions and 0 deletions
66
lib/ansible/modules/cloud/openstack/os_auth.py
Normal file
66
lib/ansible/modules/cloud/openstack/os_auth.py
Normal file
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
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()
|
Loading…
Reference in a new issue