From 04ec47bdf16112435a1278149146bdb81de2b979 Mon Sep 17 00:00:00 2001 From: Jordan Borean Date: Wed, 31 Jul 2019 08:45:37 +1000 Subject: [PATCH] win_dsc - be more lenient with datetime parsing (#59703) * win_dsc - be more lenient with datetime parsing * Remove l that shouldn't be there --- changelogs/fragments/win_dsc-datetime.yaml | 2 ++ lib/ansible/modules/windows/win_dsc.ps1 | 6 +----- lib/ansible/modules/windows/win_dsc.py | 5 +++-- 3 files changed, 6 insertions(+), 7 deletions(-) create mode 100644 changelogs/fragments/win_dsc-datetime.yaml diff --git a/changelogs/fragments/win_dsc-datetime.yaml b/changelogs/fragments/win_dsc-datetime.yaml new file mode 100644 index 00000000000..a402befd56e --- /dev/null +++ b/changelogs/fragments/win_dsc-datetime.yaml @@ -0,0 +1,2 @@ +bugfixes: +- win_dsc - Be more leniant around the accepted DateTime values for backwards compatibility - https://github.com/ansible/ansible/issues/59667 diff --git a/lib/ansible/modules/windows/win_dsc.ps1 b/lib/ansible/modules/windows/win_dsc.ps1 index 87cc73af4fa..690f391a7b4 100644 --- a/lib/ansible/modules/windows/win_dsc.ps1 +++ b/lib/ansible/modules/windows/win_dsc.ps1 @@ -19,11 +19,7 @@ Function ConvertTo-ArgSpecType { $arg_type = switch($CimType) { Boolean { "bool" } Char16 { [Func[[Object], [Char]]]{ [System.Char]::Parse($args[0].ToString()) } } - DateTime { [Func[[Object], [DateTime]]]{ - # o == ISO 8601 format - [System.DateTime]::ParseExact($args[0].ToString(), "o", [CultureInfo]::InvariantCulture, - [System.Globalization.DateTimeStyles]::None) - }} + DateTime { [Func[[Object], [DateTime]]]{ [System.DateTime]($args[0].ToString()) } } Instance { "dict" } Real32 { "float" } Real64 { [Func[[Object], [Double]]]{ [System.Double]::Parse($args[0].ToString()) } } diff --git a/lib/ansible/modules/windows/win_dsc.py b/lib/ansible/modules/windows/win_dsc.py index 4d72e64e209..86df7d5082c 100644 --- a/lib/ansible/modules/windows/win_dsc.py +++ b/lib/ansible/modules/windows/win_dsc.py @@ -54,8 +54,9 @@ options: provided but a comma separated string also work. Use a list where possible as no escaping is required and it works with more complex types list C(CimInstance[]). - - If the type of the DSC resource option is a C(DateTime), use a string in - the form of an ISO 8901 string. + - If the type of the DSC resource option is a C(DateTime), you should use + a string in the form of an ISO 8901 string to ensure the exact date is + used. - Since Ansible 2.8, Ansible will now validate the input fields against the DSC resource definition automatically. Older versions will silently ignore invalid fields.