From 4490c0ba5134daffd913a2fc61c3e3f4a341e485 Mon Sep 17 00:00:00 2001 From: ShachafGoldstein Date: Tue, 28 May 2019 22:31:00 +0300 Subject: [PATCH] correct behaviour of win_iis when using site_id if site not found (#56567) * Fixed #47057 * Fix trailing whitespace * Change for review --- ...x-win_iis_website-id assignment-for-first-new-site.yml | 2 ++ lib/ansible/modules/windows/win_iis_website.ps1 | 8 +++++++- 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/56567-Fix-win_iis_website-id assignment-for-first-new-site.yml diff --git a/changelogs/fragments/56567-Fix-win_iis_website-id assignment-for-first-new-site.yml b/changelogs/fragments/56567-Fix-win_iis_website-id assignment-for-first-new-site.yml new file mode 100644 index 00000000000..515c1c2d88f --- /dev/null +++ b/changelogs/fragments/56567-Fix-win_iis_website-id assignment-for-first-new-site.yml @@ -0,0 +1,2 @@ +bugfixes: + - "win_iis_website - site_id not used if no sites exist already and creating a new site (https://github.com/ansible/ansible/issues/47057)" \ No newline at end of file diff --git a/lib/ansible/modules/windows/win_iis_website.ps1 b/lib/ansible/modules/windows/win_iis_website.ps1 index c6093721898..7851192fd38 100644 --- a/lib/ansible/modules/windows/win_iis_website.ps1 +++ b/lib/ansible/modules/windows/win_iis_website.ps1 @@ -84,7 +84,13 @@ Try { # This is a bug in the New-WebSite commandlet. Apparently there must be at least one site configured in IIS otherwise New-WebSite crashes. # For more details, see http://stackoverflow.com/questions/3573889/ps-c-new-website-blah-throws-index-was-outside-the-bounds-of-the-array $sites_list = get-childitem -Path IIS:\sites - if ($null -eq $sites_list) { $site_parameters.ID = 1 } + if ($null -eq $sites_list) { + if ($site_id) { + $site_parameters.ID = $site_id + } else { + $site_parameters.ID = 1 + } + } $site = New-Website @site_parameters -Force $result.changed = $true