fix: check-mode in modules behaves properly

This commit is contained in:
Johanna Dorothea Reichmann 2023-01-30 13:07:34 +01:00
parent bf7f2328e9
commit 61d5e59cb8
No known key found for this signature in database
GPG key ID: 03624C433676E465
5 changed files with 30 additions and 8 deletions

View file

@ -199,10 +199,6 @@ async def run_module():
await module.fail_json(msg=missing_required_lib("matrix-nio"))
await module.matrix_login()
if module.check_mode:
return result
action = module.params["state"]
room_id = module.params["room_id"]
user_ids = module.params["user_ids"]
@ -211,6 +207,11 @@ async def run_module():
if module.params["exclusive"] and action != "member":
await module.fail_json(msg="exclusive=True can only be used with state=member")
# Handle ansible check mode
if module.check_mode:
result["members"] = user_ids
await module.exit_json(**result)
# Create client object
client = module.client

View file

@ -116,7 +116,8 @@ async def run_module():
await module.fail_json(msg=missing_required_lib("matrix-nio"))
if module.check_mode:
return result
result["changed"] = True
await module.exit_json(**result)
await module.matrix_login()
client = module.client
@ -134,6 +135,8 @@ async def run_module():
)
if isinstance(response, RoomSendError):
await module.fail_json(**result)
else:
result["changed"] = True
await module.exit_json(**result)

View file

@ -111,6 +111,11 @@ async def run_module():
await module.matrix_login()
client = module.client
if module.check_mode:
result["changed"] = True
result["room_id"] = "!fakeRoomId:localhost"
await module.exit_json(**result)
# Try to look up room_id
room_id_resp = await client.room_resolve_alias(module.params["alias"])

View file

@ -131,8 +131,11 @@ async def run_module():
client = module.client
if module.check_mode:
# TODO: Do proper check
return result
# TODO: Attempt to check if the state event is already present
# Implementation note: this might not be possible as a previous check-moded
# login token might be invalid / not provided
result["changed"] = True
await module.exit_json(**result)
failed = False

View file

@ -124,7 +124,10 @@ async def run_module():
await module.fail_json(msg=missing_required_lib("matrix-nio"))
if module.check_mode:
return result
result["changed"] = True
result["device_id"] = "FAKEDEVICE"
result["token"] = "syt_fake_token"
await module.exit_json(**result)
failed = False
@ -137,6 +140,13 @@ async def run_module():
if key is None:
await module.fail_json(msg="A key has to be provided")
# Move check-mode handling after check for missing key
if module.check_mode:
result["changed"] = True
result["device_id"] = "FAKEDEVICE"
result["token"] = "syt_fake_token"
await module.exit_json(**result)
admin = module.params["admin"]
method, path, data = Api.login(