Skip to content

Commit

Permalink
Merge pull request #485 from dezeroku/hashivault_pki_role_list_check_…
Browse files Browse the repository at this point in the history
…mode

Add check_mode support to hashivault_pki_role_list
  • Loading branch information
TerryHowe authored Jul 7, 2024
2 parents c22434d + df9d0ca commit a8fc2e0
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
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)}


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

0 comments on commit a8fc2e0

Please sign in to comment.