# Writing PowerShell modules with support for "check mode"

**URL:** <https://forum.ansible.com/t/writing-powershell-modules-with-support-for-check-mode/21549>\
**Category:** Ansible Developer\
**Tags:** windows\
**Created:** [May 24, 2016, 5:26pm UTC](https://forum.ansible.com/t/writing-powershell-modules-with-support-for-check-mode/21549 "2016-05-24T17:26:38Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Trond\_Hindenes](https://avatars.discourse-cdn.com/v4/letter/t/96bed5/32.png) [@Trond\_Hindenes](https://forum.ansible.com/u/Trond_Hindenes)\
**Post date:** [May 24, 2016, 5:26pm UTC](https://forum.ansible.com/t/writing-powershell-modules-with-support-for-check-mode/21549/1 "2016-05-24T17:26:38Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [May 24, 2016, 5:51pm UTC](https://forum.ansible.com/t/writing-powershell-modules-with-support-for-check-mode/21549/2 "2016-05-24T17:51:20Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Trond\_Hindenes](https://avatars.discourse-cdn.com/v4/letter/t/96bed5/32.png) [@Trond\_Hindenes](https://forum.ansible.com/u/Trond_Hindenes)\
**Post date:** [May 24, 2016, 6:00pm UTC](https://forum.ansible.com/t/writing-powershell-modules-with-support-for-check-mode/21549/3 "2016-05-24T18:00:18Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [May 24, 2016, 6:02pm UTC](https://forum.ansible.com/t/writing-powershell-modules-with-support-for-check-mode/21549/4 "2016-05-24T18:02:57Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Trond\_Hindenes](https://avatars.discourse-cdn.com/v4/letter/t/96bed5/32.png) [@Trond\_Hindenes](https://forum.ansible.com/u/Trond_Hindenes)\
**Post date:** [May 24, 2016, 6:43pm UTC](https://forum.ansible.com/t/writing-powershell-modules-with-support-for-check-mode/21549/5 "2016-05-24T18:43:45Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [May 24, 2016, 7:04pm UTC](https://forum.ansible.com/t/writing-powershell-modules-with-support-for-check-mode/21549/6 "2016-05-24T19:04:29Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Trond\_Hindenes](https://avatars.discourse-cdn.com/v4/letter/t/96bed5/32.png) [@Trond\_Hindenes](https://forum.ansible.com/u/Trond_Hindenes)\
**Post date:** [May 24, 2016, 7:26pm UTC](https://forum.ansible.com/t/writing-powershell-modules-with-support-for-check-mode/21549/7 "2016-05-24T19:26:32Z")

</div>

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!
