summaryrefslogtreecommitdiffstats
path: root/ansible_collections/openstack/cloud/plugins/modules/keypair.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-18 05:52:35 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-18 05:52:35 +0000
commit7fec0b69a082aaeec72fee0612766aa42f6b1b4d (patch)
treeefb569b86ca4da888717f5433e757145fa322e08 /ansible_collections/openstack/cloud/plugins/modules/keypair.py
parentReleasing progress-linux version 7.7.0+dfsg-3~progress7.99u1. (diff)
downloadansible-7fec0b69a082aaeec72fee0612766aa42f6b1b4d.tar.xz
ansible-7fec0b69a082aaeec72fee0612766aa42f6b1b4d.zip
Merging upstream version 9.4.0+dfsg.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'ansible_collections/openstack/cloud/plugins/modules/keypair.py')
-rw-r--r--ansible_collections/openstack/cloud/plugins/modules/keypair.py82
1 files changed, 52 insertions, 30 deletions
diff --git a/ansible_collections/openstack/cloud/plugins/modules/keypair.py b/ansible_collections/openstack/cloud/plugins/modules/keypair.py
index 232d4985e..1e75ae3bc 100644
--- a/ansible_collections/openstack/cloud/plugins/modules/keypair.py
+++ b/ansible_collections/openstack/cloud/plugins/modules/keypair.py
@@ -1,4 +1,5 @@
#!/usr/bin/python
+# -*- coding: utf-8 -*-
# Copyright (c) 2014 Hewlett-Packard Development Company, L.P.
# Copyright (c) 2013, Benno Joy <benno@ansible.com>
@@ -36,10 +37,6 @@ options:
choices: [present, absent, replace]
default: present
type: str
-requirements:
- - "python >= 3.6"
- - "openstacksdk"
-
extends_documentation_fragment:
- openstack.cloud.openstack
'''
@@ -60,23 +57,49 @@ EXAMPLES = '''
'''
RETURN = '''
-id:
- description: Unique UUID.
- returned: success
- type: str
-name:
- description: Name given to the keypair.
- returned: success
- type: str
-public_key:
- description: The public key value for the keypair.
- returned: success
- type: str
-private_key:
- description: The private key value for the keypair.
- returned: Only when a keypair is generated for the user (e.g., when creating one
- and a public key is not specified).
- type: str
+keypair:
+ description: Dictionary describing the keypair.
+ returned: On success when I(state) is 'present'
+ type: dict
+ contains:
+ created_at:
+ description: Date the keypair was created
+ returned: success
+ type: str
+ fingerprint:
+ description: The short fingerprint associated with the public_key
+ for this keypair.
+ returned: success
+ type: str
+ id:
+ description: Unique UUID.
+ returned: success
+ type: str
+ is_deleted:
+ description: Whether the keypair is deleted or not
+ returned: success
+ type: bool
+ name:
+ description: Name given to the keypair.
+ returned: success
+ type: str
+ private_key:
+ description: The private key value for the keypair.
+ returned: Only when a keypair is generated for the user (e.g., when
+ creating one and a public key is not specified).
+ type: str
+ public_key:
+ description: The public key value for the keypair.
+ returned: success
+ type: str
+ type:
+ description: The type of keypair
+ returned: success
+ type: str
+ user_id:
+ description: The user id for a keypair
+ returned: success
+ type: str
'''
from ansible_collections.openstack.cloud.plugins.module_utils.openstack import (
@@ -84,12 +107,11 @@ from ansible_collections.openstack.cloud.plugins.module_utils.openstack import (
class KeyPairModule(OpenStackModule):
- deprecated_names = ('os_keypair', 'openstack.cloud.os_keypair')
argument_spec = dict(
name=dict(required=True),
- public_key=dict(default=None),
- public_key_file=dict(default=None),
+ public_key=dict(),
+ public_key_file=dict(),
state=dict(default='present',
choices=['absent', 'present', 'replace']),
)
@@ -115,11 +137,12 @@ class KeyPairModule(OpenStackModule):
with open(self.params['public_key_file']) as public_key_fh:
public_key = public_key_fh.read()
- keypair = self.conn.get_keypair(name)
+ keypair = self.conn.compute.find_keypair(name)
if self.ansible.check_mode:
self.exit_json(changed=self._system_state_change(keypair))
+ changed = False
if state in ('present', 'replace'):
if keypair and keypair['name'] == name:
if public_key and (public_key != keypair['public_key']):
@@ -129,20 +152,19 @@ class KeyPairModule(OpenStackModule):
" as offered. Delete key first." % name
)
else:
- self.conn.delete_keypair(name)
+ self.conn.compute.delete_keypair(keypair)
keypair = self.conn.create_keypair(name, public_key)
changed = True
- else:
- changed = False
else:
keypair = self.conn.create_keypair(name, public_key)
changed = True
- self.exit_json(changed=changed, key=keypair, id=keypair['id'])
+ self.exit_json(
+ changed=changed, keypair=keypair.to_dict(computed=False))
elif state == 'absent':
if keypair:
- self.conn.delete_keypair(name)
+ self.conn.compute.delete_keypair(keypair)
self.exit_json(changed=True)
self.exit_json(changed=False)