diff --git a/ansible/modules/hashivault/hashivault_pki_role_list.py b/ansible/modules/hashivault/hashivault_pki_role_list.py index b43bc2db..4b572ce8 100755 --- a/ansible/modules/hashivault/hashivault_pki_role_list.py +++ b/ansible/modules/hashivault/hashivault_pki_role_list.py @@ -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'): @@ -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__': diff --git a/functional/test_pki.yml b/functional/test_pki.yml index 6ca3b1f2..442eaa1c 100644 --- a/functional/test_pki.yml +++ b/functional/test_pki.yml @@ -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}}" @@ -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}}"