Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add check_mode support to hashivault_pki_role_list #485

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions ansible/modules/hashivault/hashivault_pki_role_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def main():
argspec = hashivault_argspec()
argspec['mount_point'] = dict(required=False, type='str', default='pki')

module = hashivault_init(argspec)
module = hashivault_init(argspec, supports_check_mode=True)
result = hashivault_pki_role_list(module)

if result.get('failed'):
Expand All @@ -62,8 +62,8 @@ def hashivault_pki_role_list(module):

try:
return {'data': client.secrets.pki.list_roles(mount_point=mount_point).get('data').get('keys')}
except Exception:
return {'data': []}
except Exception as e:
return {'failed': True, 'data': [], 'msg': str(e)}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if it's cleaner to drop data completely for the failed case output or return an empty list?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if any other getters support check mode to have a pattern

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.



if __name__ == '__main__':
Expand Down
27 changes: 27 additions & 0 deletions functional/test_pki.yml
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,32 @@
- response.rc == 0
- response.changed == True

- name: List Roles check_mode expect_fail
hashivault_pki_role_list:
mount_point: "no_such_mount_point"
check_mode: true
register: response
failed_when: not response.failed
- assert:
that:
- response.rc == 0
- response.changed == False
- response.msg is defined
- response.msg != None
- |
"no_such_mount_point" in response.msg
- name: List Roles check_mode
hashivault_pki_role_list:
mount_point: "{{mount_inter}}"
check_mode: true
register: response
- assert:
that:
- response.rc == 0
- response.changed == False
- response.data is defined
- response.data != None
- role in response.data
- name: List Roles
hashivault_pki_role_list:
mount_point: "{{mount_inter}}"
Expand All @@ -288,6 +314,7 @@
- response.data is defined
- response.data != None
- role in response.data

- name: Read Role
hashivault_pki_role_get:
mount_point: "{{mount_inter}}"
Expand Down
Loading