From 9d04d781b3a2250afba7aae098ef61221f2e013e Mon Sep 17 00:00:00 2001 From: Jordan Borean Date: Mon, 27 Jan 2025 07:40:21 +1000 Subject: [PATCH] setup - remvoe dep on shared function (#752) Remove the dep on ConvertFrom-AnsibleJson so that we can start to deprecate that function in Ansible exec wrapper. This is the only instance where it is used outside of the exec wrapper and it can easily be replaced by the custom PSCustomObject enumerator. Luckily this code path is not used by any of our supported connection plugins. It may be used by other connection types that cannot pipeline or through local debugging. --- changelogs/fragments/setup-json.yml | 2 ++ galaxy.yml | 2 +- plugins/modules/setup.ps1 | 23 ++++++++++++++++------- 3 files changed, 19 insertions(+), 8 deletions(-) create mode 100644 changelogs/fragments/setup-json.yml diff --git a/changelogs/fragments/setup-json.yml b/changelogs/fragments/setup-json.yml new file mode 100644 index 00000000..4e8c13ef --- /dev/null +++ b/changelogs/fragments/setup-json.yml @@ -0,0 +1,2 @@ +minor_changes: + - setup - Remove dependency on shared function loaded by Ansible diff --git a/galaxy.yml b/galaxy.yml index e96d58b6..faef893c 100644 --- a/galaxy.yml +++ b/galaxy.yml @@ -1,6 +1,6 @@ namespace: ansible name: windows -version: 2.7.0 +version: 2.8.0 readme: README.md authors: - Jordan Borean @jborean93 diff --git a/plugins/modules/setup.ps1 b/plugins/modules/setup.ps1 index e7f751d9..8a0fbc12 100644 --- a/plugins/modules/setup.ps1 +++ b/plugins/modules/setup.ps1 @@ -25,20 +25,29 @@ $spec = @{ # This module can be called by the gather_facts action plugin in ansible-base. While it shouldn't add any new options # we need to make sure the module doesn't break if it does. To do this we need to add any options in the input args if ($args.Length -gt 0) { - $params = Get-Content -LiteralPath $args[0] | ConvertFrom-AnsibleJson + $params = Get-Content $args[0] | ConvertFrom-Json + if ($params) { + foreach ($prop in $params.PSObject.Properties.Name) { + if ($prop.StartsWith('_') -or $spec.options.ContainsKey($prop)) { + continue + } + $spec.options.$prop = @{ type = 'raw' } + } + } } else { $params = $complex_args -} -if ($params) { - foreach ($param in $params.GetEnumerator()) { - if ($param.Key.StartsWith('_') -or $spec.options.ContainsKey($param.Key)) { - continue + if ($params) { + foreach ($param in $params.GetEnumerator()) { + if ($param.Key.StartsWith('_') -or $spec.options.ContainsKey($param.Key)) { + continue + } + $spec.options."$($param.Key)" = @{ type = 'raw' } } - $spec.options."$($param.Key)" = @{ type = 'raw' } } } + $module = [Ansible.Basic.AnsibleModule]::Create($args, $spec) $measureSubset = $module.Params._measure_subset