From fd4b282f6f14fa917a40ddf13e414519c300e81b Mon Sep 17 00:00:00 2001 From: Jordan Borean Date: Sat, 17 Nov 2018 18:15:36 +1000 Subject: [PATCH] Ansible.Basic.cs - fix check mode run with nested spec (#48838) --- .../module_utils/csharp/Ansible.Basic.cs | 3 ++- .../library/ansible_basic_tests.ps1 | 22 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/lib/ansible/module_utils/csharp/Ansible.Basic.cs b/lib/ansible/module_utils/csharp/Ansible.Basic.cs index 064daac2e1..ed21d22896 100644 --- a/lib/ansible/module_utils/csharp/Ansible.Basic.cs +++ b/lib/ansible/module_utils/csharp/Ansible.Basic.cs @@ -700,7 +700,8 @@ namespace Ansible.Basic // initially parse the params and check for unsupported ones and set internal vars CheckUnsupportedArguments(param, legalInputs); - if (CheckMode && !(bool)spec["supports_check_mode"]) + // Only run this check if we are at the root argument (optionsContext.Count == 0) + if (CheckMode && !(bool)spec["supports_check_mode"] && optionsContext.Count == 0) { Result["skipped"] = true; Result["msg"] = String.Format("remote module ({0}) does not support check mode", ModuleName); diff --git a/test/integration/targets/win_csharp_utils/library/ansible_basic_tests.ps1 b/test/integration/targets/win_csharp_utils/library/ansible_basic_tests.ps1 index 1caf0ae69d..fe867fe048 100644 --- a/test/integration/targets/win_csharp_utils/library/ansible_basic_tests.ps1 +++ b/test/integration/targets/win_csharp_utils/library/ansible_basic_tests.ps1 @@ -1352,6 +1352,28 @@ test_no_log - Invoked with: $actual.invocation | Assert-DictionaryEquals -Expected @{module_args = @{option_key = "abc"}} } + "Check mode with suboption without supports_check_mode" = { + $spec = @{ + options = @{ + sub_options = @{ + # This tests the situation where a sub key doesn't set supports_check_mode, the logic in + # Ansible.Basic automatically sets that to $false and we want it to ignore it for a nested check + type = "dict" + options = @{ + sub_option = @{ type = "str"; default = "value" } + } + } + } + supports_check_mode = $true + } + $complex_args = @{ + _ansible_check_mode = $true + } + + $m = [Ansible.Basic.AnsibleModule]::Create(@(), $spec) + $m.CheckMode | Assert-Equals -Expected $true + } + "Type conversion error" = { $spec = @{ options = @{