Writing PowerShell modules with support for "check mode"

I’d like to support “check mode” in some of my PowerShell-based modules for Ansible on Windows.
Is this currently supported? We’re not using the AnsibleModule object at all, so how can I implement this? Any thought and pointers appreciated.

In ansible 2.0+ a new argument is passed to all modules called _ansible_check_mode. That is a boolean, and the module can interpret and do what it wants.

Based on that value, and whether you indicate in someway that check mode is supported, then you could exit (not fail) with the same message as the python modules which is:

self.exit_json(skipped=True, msg=“remote module does not support check mode”)

I’m sure it might be useful to come up with a standard. Maybe a proposal? Matt Davis probably has some plans around a better PowerShell version of AnsibleModule.

Thanks Matt, that works!
I was under the impression that Ansible checked wether the module supports check-mode before it executes it, but that’s probably where I was wrong.

Yeah, that code path happens in AnsibleModule, which is not evaluated until the module actually executes.

There are some cases where an action plugin may bail early, but generally the above applies.

H, still can’t figure this out. So if I just run a custom module with --check Ansible will skip that task. So there has to be something which tells Ansible whether or not to execute that task before it is sent to the target node, no? Maybe I’m just slow…

Can you give more details on how you are doing this? I just tried with a custom binary module, and it seemed to work fine.

I also see that the powershell.ps1 module_utils code also already supports check mode via Parse-Args.

If you run with -v while providing --check, what is the specific error that you are seeing?

Might it be related to Parse-Args already supporting this, and you not passing $true, to Parse-Args?

Ah, got it. Thanks again, my Ansible-fu is rusty and I really wanted to figure out this. Parse-Args does indeed have a flag to set whether the module supports check mode. It’s coming along now. Thanks again!