mirror of
https://opendev.org/openstack/ansible-collections-openstack.git
synced 2026-07-28 18:54:29 +00:00
Move keypair module to proxy layer
Update keypair module to new openstacksdk Change-Id: I8f29d983b176e83fbca1919be34a86fe4756aa5e
This commit is contained in:
committed by
Rafael Castillo
parent
81a81ad759
commit
6d8c965333
@@ -6,6 +6,12 @@
|
|||||||
state: present
|
state: present
|
||||||
register: keypair
|
register: keypair
|
||||||
|
|
||||||
|
- name: Assert fields
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- item in keypair.keypair
|
||||||
|
loop: "{{ expected_fields }}"
|
||||||
|
|
||||||
- name: Get list of all keypairs
|
- name: Get list of all keypairs
|
||||||
openstack.cloud.keypair_info:
|
openstack.cloud.keypair_info:
|
||||||
cloud: "{{ cloud }}"
|
cloud: "{{ cloud }}"
|
||||||
@@ -32,7 +38,7 @@
|
|||||||
- name: Ensure public key is returned
|
- name: Ensure public key is returned
|
||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
- keypair.key.public_key is defined and keypair.key.public_key
|
- keypair.keypair.public_key is defined and keypair.keypair.public_key
|
||||||
|
|
||||||
- name: Create another keypair
|
- name: Create another keypair
|
||||||
openstack.cloud.keypair:
|
openstack.cloud.keypair:
|
||||||
|
|||||||
@@ -61,23 +61,49 @@ EXAMPLES = '''
|
|||||||
'''
|
'''
|
||||||
|
|
||||||
RETURN = '''
|
RETURN = '''
|
||||||
id:
|
keypair:
|
||||||
description: Unique UUID.
|
description: Dictionary describing the keypair.
|
||||||
returned: success
|
returned: On success when I(state) is 'present'
|
||||||
type: str
|
type: dict
|
||||||
name:
|
contains:
|
||||||
description: Name given to the keypair.
|
created_at:
|
||||||
returned: success
|
description: Date the keypair was created
|
||||||
type: str
|
returned: success
|
||||||
public_key:
|
type: str
|
||||||
description: The public key value for the keypair.
|
fingerprint:
|
||||||
returned: success
|
description: The short fingerprint associated with the public_key
|
||||||
type: str
|
for this keypair.
|
||||||
private_key:
|
returned: success
|
||||||
description: The private key value for the keypair.
|
type: str
|
||||||
returned: Only when a keypair is generated for the user (e.g., when creating one
|
id:
|
||||||
and a public key is not specified).
|
description: Unique UUID.
|
||||||
type: str
|
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 (
|
from ansible_collections.openstack.cloud.plugins.module_utils.openstack import (
|
||||||
@@ -115,11 +141,12 @@ class KeyPairModule(OpenStackModule):
|
|||||||
with open(self.params['public_key_file']) as public_key_fh:
|
with open(self.params['public_key_file']) as public_key_fh:
|
||||||
public_key = public_key_fh.read().rstrip()
|
public_key = public_key_fh.read().rstrip()
|
||||||
|
|
||||||
keypair = self.conn.get_keypair(name)
|
keypair = self.conn.compute.find_keypair(name)
|
||||||
|
|
||||||
if self.ansible.check_mode:
|
if self.ansible.check_mode:
|
||||||
self.exit_json(changed=self._system_state_change(keypair))
|
self.exit_json(changed=self._system_state_change(keypair))
|
||||||
|
|
||||||
|
changed = False
|
||||||
if state in ('present', 'replace'):
|
if state in ('present', 'replace'):
|
||||||
if keypair and keypair['name'] == name:
|
if keypair and keypair['name'] == name:
|
||||||
if public_key and (public_key != keypair['public_key']):
|
if public_key and (public_key != keypair['public_key']):
|
||||||
@@ -129,20 +156,19 @@ class KeyPairModule(OpenStackModule):
|
|||||||
" as offered. Delete key first." % name
|
" as offered. Delete key first." % name
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
self.conn.delete_keypair(name)
|
self.conn.compute.delete_keypair(keypair)
|
||||||
keypair = self.conn.create_keypair(name, public_key)
|
keypair = self.conn.create_keypair(name, public_key)
|
||||||
changed = True
|
changed = True
|
||||||
else:
|
|
||||||
changed = False
|
|
||||||
else:
|
else:
|
||||||
keypair = self.conn.create_keypair(name, public_key)
|
keypair = self.conn.create_keypair(name, public_key)
|
||||||
changed = True
|
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':
|
elif state == 'absent':
|
||||||
if keypair:
|
if keypair:
|
||||||
self.conn.delete_keypair(name)
|
self.conn.compute.delete_keypair(keypair)
|
||||||
self.exit_json(changed=True)
|
self.exit_json(changed=True)
|
||||||
self.exit_json(changed=False)
|
self.exit_json(changed=False)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user