Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Virtual Directories #356

Open
flkdnt opened this issue Dec 6, 2022 · 1 comment
Open

Virtual Directories #356

flkdnt opened this issue Dec 6, 2022 · 1 comment

Comments

@flkdnt
Copy link

flkdnt commented Dec 6, 2022

Bug Report

Describe the Bug

  1. Powershell cannot run the IIS Specific Commands without importing the WebAdministration module if IIS Commands havn't already been run in the current powershell session/puppet run.

When Creating or Updating a Virtual Directory

  • Where the PhysicalPath is a UNC path AND
  • Where the Application Parameter is Specified:
  1. The CREATE function Errors: 

Debug: STDOUT: New-Item : A parameter cannot be found that matches parameter name 'Application'.

  1. The UPDATE Function Errors: 

Debug: STDOUT: Set-ItemProperty : Property application is not found on <PATH>

The reason for these errors is:

  • New-Item does not have the parameter -Application
  • Set-ItemProperty cannot use the property application when the Virtual Directory was created with New-Item because that property doesn't get created by New-Item

Expected Behavior

The Virtual Directory gets created in IIS

Steps to Reproduce

  1. Add a virtual directory from a folder from a network share, with the application parameter set:
iis_virtual_directory { 'NAME':
    ensure       => 'present',
    name         => 'NAME',
    sitename     => 'SITE',
    application  => 'APPLICATION,
    physicalpath => 'Z:\\FOLDER\\PATH',
}
  1. run puppet, i.e. puppet agent -t

Environment

  • Version: N/A
  • Platform: Windows

Additional Context

The following is how I fixed the file webadministration.rb in my local environment:

Change function

Line 34:

  • Change cmd = [] to cmd = ["Import-Module WebAdministration;","Start-Sleep -Seconds 5;"] to fix bug 1

Line 42:

  • Add logic in case @resource[:application] exists to build the Path as @resource[:sitename]\\@resource[:application] to avoid repeat corrective runs:
if @resource[:application]
  cmd << "New-Item -Type VirtualDirectory -Name 'IIS:\\Sites\\#{@resource[:sitename]}\\#{@resource[:application]}\\#{@resource[:name]}' "
else
  cmd << "New-Item -Type VirtualDirectory -Name 'IIS:\\Sites\\#{@resource[:sitename]}\\#{@resource[:name]}' "
end
  • Add the '-Name' Parameter in New-Item

Line 44:

  • Move cmd << "-Application \"#{@resource[:application]}\" " if @resource[:application] Between Line 38 and Line 39

Line 67:

  • Change cmd = [] to cmd = ["Import-Module WebAdministration;","Start-Sleep -Seconds 5;"] to fix bug 1

Update function

Line 70:

Suggestion - To handle or eliminate the error that occurs when "application" isn't in the Item Property of the Virtual Directory and application is specified: Adding -ErrorAction SilentlyContinue to the current command is a workaround. A more permanent solution would be to filter on the attribute 'application' from the Item-property, like this: Import-Module WebAdministration;Start-Sleep -Seconds 5;Get-ItemProperty -Path PATH | Get-Member -MemberType NoteProperty and only run the command if it exists.

Line 87:

  • Change cmd = [] to cmd = ["Import-Module WebAdministration;","Start-Sleep -Seconds 5;"] to fix bug 1
@jordanbreen28
Copy link
Contributor

jordanbreen28 commented Mar 9, 2023

@flkdnt thanks for raising this. We are accepting PRs to this repo, so if you want to implement your proposed changes feel free to do so. Otherwise I'll label this issue so It can be prioritised correctly by our team :-) Thanks again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants