【问题标题】:Installing IIS as a step in Octopus Deploy在 Octopus Deploy 中安装 IIS 作为一个步骤
【发布时间】:2018-08-22 10:47:52
【问题描述】:

我正在尝试向我的Octopus Deployment 添加一个步骤,如果目标上没有安装 IIS,它将安装它,但我找不到任何东西。如果目前没有任何东西,是否有我可以使用的 powershell 脚本将Web Server (IIS) 角色/功能添加到机器?

这将使启动安装了最少功能的新虚拟机变得更加容易,然后在部署特定应用程序时,他们可以管理是否需要 IIS,而不是手动将其添加到适当的机器。

提前致谢!

【问题讨论】:

标签: powershell iis octopus-deploy octopus


【解决方案1】:

您可以使用Enable-WindowsOptionalFeatureInstall-WindowsFeature,具体取决于您正在配置的机器。一个快速的谷歌搜索引导我here

这里有一个例子来检查是否安装了 IIS,如果没有则安装

 if ((Get-WindowsFeature Web-Server).InstallState -eq "Installed") {
        Write-Host "IIS is installed on $vm"
    } 
    else {
        Write-Host "IIS is not installed on $vm"
        Write-Host "Installing IIS.."
        Install-WindowsFeature -name Web-Server -IncludeManagementTools
    }

【讨论】:

    【解决方案2】:

    在挖掘 Octopus 上可用的模板后,我刚刚找到了一个解决方案,WesleySSmith 有一个名为Windows - Ensure Features Installed 的步骤模板,可​​以添加到您的流程中。它允许您提供要安装的功能名称,例如IIS-WebServer

    对于 PowerShell 狂热者来说,此时此步骤背后的脚本如下所示:

    $requiredFeatures = $OctopusParameters['WindowsFeatures'].split(",") | foreach { 
    
    $_.trim() }
    if(! $requiredFeatures) {
        Write-Output "No required Windows Features specified..."
        exit
    }
    $requiredFeatures | foreach { $feature = DISM.exe /ONLINE /Get-FeatureInfo /FeatureName:$_; if($feature -like "*Feature name $_ is unknown*") { throw $feature } }
    
    Write-Output "Retrieving all Windows Features..."
    $allFeatures = DISM.exe /ONLINE /Get-Features /FORMAT:List | Where-Object { $_.StartsWith("Feature Name") -OR $_.StartsWith("State") } 
    $features = new-object System.Collections.ArrayList
    for($i = 0; $i -lt $allFeatures.length; $i=$i+2) {
        $feature = $allFeatures[$i]
        $state = $allFeatures[$i+1]
        $features.add(@{feature=$feature.split(":")[1].trim();state=$state.split(":")[1].trim()}) | OUT-NULL
    }
    
    Write-Output "Checking for missing Windows Features..."
    $missingFeatures = new-object System.Collections.ArrayList
    $features | foreach { if( $requiredFeatures -contains $_.feature -and $_.state -eq 'Disabled') { $missingFeatures.add($_.feature) | OUT-NULL } }
    if(! $missingFeatures) {
        Write-Output "All required Windows Features are installed"
        exit
    }
    Write-Output "Installing missing Windows Features..."
    $featureNameArgs = ""
    $missingFeatures | foreach { $featureNameArgs = $featureNameArgs + " /FeatureName:" + $_ }
    $dism = "DISM.exe"
    IF ($SuppressReboot)
    {
        $arguments = "/NoRestart "
    }
    ELSE
    {
        $arguments = ""
    }
    $arguments = $arguments + "/ONLINE /Enable-Feature $featureNameArgs"
    IF ($Source)
    {
        if (!(Test-Path $Source)) {
            throw "Could not find the file $Source or access denied"
        }
        $arguments = $arguments + " /Source:$Source"
    }
    Write-Output "Calling DISM with arguments: $arguments"
    start-process -NoNewWindow $dism $arguments
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多