diff --git a/changelogs/fragments/76924-powershell-ansible.basic-support-non-windows.yml b/changelogs/fragments/76924-powershell-ansible.basic-support-non-windows.yml new file mode 100644 index 00000000000..c5e02591891 --- /dev/null +++ b/changelogs/fragments/76924-powershell-ansible.basic-support-non-windows.yml @@ -0,0 +1,3 @@ +--- +minor_changes: + - Ansible.Basic - small changes to allow use in PowerShell modules running on non-Windows platforms (https://github.com/ansible/ansible/pull/76924). diff --git a/lib/ansible/module_utils/csharp/Ansible.Basic.cs b/lib/ansible/module_utils/csharp/Ansible.Basic.cs index 51a543bc135..2db9728ddc5 100644 --- a/lib/ansible/module_utils/csharp/Ansible.Basic.cs +++ b/lib/ansible/module_utils/csharp/Ansible.Basic.cs @@ -128,6 +128,7 @@ namespace Ansible.Basic { if (tmpdir == null) { +#if WINDOWS SecurityIdentifier user = WindowsIdentity.GetCurrent().User; DirectorySecurity dirSecurity = new DirectorySecurity(); dirSecurity.SetOwner(user); @@ -183,6 +184,9 @@ namespace Ansible.Basic if (!KeepRemoteFiles) cleanupFiles.Add(tmpdir); +#else + throw new NotImplementedException("Tmpdir is only supported on Windows"); +#endif } return tmpdir; } @@ -339,6 +343,7 @@ namespace Ansible.Basic if (NoLog) return; +#if WINDOWS string logSource = "Ansible"; bool logSourceExists = false; try @@ -378,6 +383,10 @@ namespace Ansible.Basic warnings.Add(String.Format("Unknown error when creating event log entry: {0}", e.Message)); } } +#else + // Windows Event Log is only available on Windows + return; +#endif } public void Warn(string message)