无法通过木偶申请DSC

时间:2016-09-23 23:12:24

标签: windows powershell puppet dsc

环境:Windows 10,包含Powershell v5

有以下应该在IIS中创建AppPool的puppet清单。

class mywebserver {
      dsc_xWebAppPool {'DefaultWebAppPool2':
            dsc_name   => 'DefaultAppPool2',
            dsc_ensure => 'Present',
            dsc_state  => 'Started',
            } 
}

注意:如果我直接在powershell中运行类似的DSC配置,它可以正常工作。

当我使用puppet应用该配置时:

puppet apply modules\mywebserver\examples\init.pp --debug -l c:\temp\log.txt 

我收到以下输出...并且流程永远不会完成...

2016-09-23 06:55:57 -0500 Puppet (debug): Runtime environment: puppet_version=4.6.2, ruby_version=2.1.9, run_mode=user, default_encoding=IBM437
...clipped...
2016-09-23 06:55:57 -0500 Facter (debug): fact "facterversion" has resolved to "3.4.1".
2016-09-23 06:55:57 -0500 Facter (debug): fact "aio_agent_version" has resolved to "1.6.2".
2016-09-23 06:55:57 -0500 Facter (debug): initializing WMI
2016-09-23 06:55:57 -0500 Facter (debug): searching "C:\ProgramData\PuppetLabs\facter\facts.d" for external facts.
2016-09-23 06:55:57 -0500 Facter (debug): searching "C:/ProgramData/PuppetLabs/puppet/cache/facts.d" for external facts.
2016-09-23 06:55:57 -0500 Facter (debug): no external facts were found.
2016-09-23 06:55:57 -0500 Facter (debug): setting fact "env_windows_installdir" based on the value of environment variable "FACTER_env_windows_installdir".
2016-09-23 06:55:57 -0500 Facter (debug): fact "env_windows_installdir" has resolved to "C:\Program Files\Puppet Labs\Puppet".
2016-09-23 06:55:57 -0500 Facter (debug): loading all custom facts.
...clipped...
2016-09-23 06:55:58 -0500 Facter (debug): searching for operatingsystem.rb in C:/ProgramData\PuppetLabs\code\environments\production\modules\chocolatey\lib\facter.
2016-09-23 06:55:58 -0500 Facter (debug): searching for operatingsystem.rb in C:/ProgramData\PuppetLabs\code\environments\production\modules\dsc\lib\facter.
2016-09-23 06:55:58 -0500 Facter (debug): searching for operatingsystem.rb in C:/ProgramData\PuppetLabs\code\environments\production\modules\iis\lib\facter.
2016-09-23 06:55:58 -0500 Facter (debug): searching for operatingsystem.rb in C:/ProgramData\PuppetLabs\code\environments\production\modules\ruby\lib\facter.
2016-09-23 06:55:58 -0500 Facter (debug): searching for operatingsystem.rb in C:/ProgramData\PuppetLabs\code\environments\production\modules\stdlib\lib\facter.
2016-09-23 06:55:58 -0500 Facter (debug): searching for operatingsystem.rb in C:/ProgramData\PuppetLabs\puppet\cache\lib\facter.
2016-09-23 06:55:58 -0500 Facter (debug): searching for operatingsystem.rb in C:/ProgramData\PuppetLabs\code\environments\production\modules\chocolatey\lib\facter.
2016-09-23 06:55:58 -0500 Facter (debug): searching for operatingsystem.rb in C:/ProgramData\PuppetLabs\code\environments\production\modules\dsc\lib\facter.
2016-09-23 06:55:58 -0500 Facter (debug): searching for operatingsystem.rb in C:/ProgramData\PuppetLabs\code\environments\production\modules\iis\lib\facter.
2016-09-23 06:55:58 -0500 Facter (debug): searching for operatingsystem.rb in C:/ProgramData\PuppetLabs\code\environments\production\modules\ruby\lib\facter.
2016-09-23 06:55:58 -0500 Facter (debug): searching for operatingsystem.rb in C:/ProgramData\PuppetLabs\code\environments\production\modules\stdlib\lib\facter.
2016-09-23 06:55:58 -0500 Facter (debug): searching for operatingsystem.rb in C:/ProgramData\PuppetLabs\puppet\cache\lib\facter.
2016-09-23 06:55:58 -0500 Facter (debug): resolving operating system facts.
2016-09-23 06:55:58 -0500 Facter (debug): resolving kernel facts.
2016-09-23 06:55:58 -0500 Facter (debug): fact "kernel" has resolved to "windows".
2016-09-23 06:55:58 -0500 Facter (debug): fact "kernelrelease" has resolved to "10.0.14393".
2016-09-23 06:55:58 -0500 Facter (debug): fact "kernelmajversion" has resolved to "10.0".
2016-09-23 06:55:58 -0500 Facter (debug): fact "kernelversion" has resolved to "10.0.14393".
2016-09-23 06:55:58 -0500 Facter (debug): fact "osfamily" has resolved to "windows".
2016-09-23 06:55:58 -0500 Facter (debug): fact "operatingsystemmajrelease" has resolved to "10.0.14393".
2016-09-23 06:55:58 -0500 Facter (debug): fact "operatingsystemrelease" has resolved to "10.0.14393".
2016-09-23 06:55:58 -0500 Facter (debug): fact "hardwaremodel" has resolved to "x86_64".
2016-09-23 06:55:58 -0500 Facter (debug): fact "architecture" has resolved to "x64".
2016-09-23 06:55:58 -0500 Facter (debug): fact "operatingsystem" has resolved to "windows".
2016-09-23 06:55:58 -0500 Facter (debug): fact "system32" has resolved to "C:\WINDOWS\system32".
... clipped ...
2016-09-23 06:55:59 -0500 Facter (debug): fact "choco_install_path" has resolved to "C:\ProgramData\chocolatey".
2016-09-23 06:55:59 -0500 Facter (debug): executing command: C:\WINDOWS\system32\cmd.exe /c C:\ProgramData\chocolatey\bin\choco.exe -v
2016-09-23 06:55:59 -0500 Facter (debug): 0.10.1
2016-09-23 06:55:59 -0500 Facter (debug): process exited with exit code 0.
2016-09-23 06:55:59 -0500 Facter (debug): fact "chocolateyversion" has resolved to "0.10.1".
... clipped ...
2016-09-23 06:55:59 -0500 Facter (debug): fact "gemhome" has resolved to "C:/Program Files/Puppet Labs/Puppet/sys/ruby/lib/ruby/gems/2.1.0".
2016-09-23 06:55:59 -0500 Facter (debug): fact "iis_version" has resolved to "10.0".
2016-09-23 06:55:59 -0500 Facter (debug): fact "puppetversion" has resolved to "4.6.2".
2016-09-23 06:55:59 -0500 Facter (debug): fact "pe_version" resolved to null and will not be added.
... clipped ...
2016-09-23 06:56:00 -0500 Facter (debug): fact "identity" has resolved to {
  privileged => true,
  user => "MyUserName"
}.
... clipped ...
2016-09-23 06:56:01 -0500 Puppet (notice): Compiled catalog for valera-mac.southslope.net in environment production in 0.21 seconds
2016-09-23 06:56:01 -0500 Puppet (debug): Creating default schedules
2016-09-23 06:56:01 -0500 Puppet (debug): Loaded state in 0.06 seconds
2016-09-23 06:56:01 -0500 Puppet (debug): Loaded transaction store file in 0.01 seconds
2016-09-23 06:56:01 -0500 Puppet (info): Applying configuration version '1474631760'
2016-09-23 06:56:01 -0500 Puppet (debug): Reloading posix reboot provider
2016-09-23 06:56:01 -0500 Puppet (debug): PowerShell Version: 5.1.14393.0
2016-09-23 06:56:01 -0500 Puppet (debug): 
$script:ErrorActionPreference = 'Stop'
$script:WarningPreference     = 'SilentlyContinue'

function new-pscredential
{
  [CmdletBinding()]
  param (
    [parameter(Mandatory=$true,
      ValueFromPipelineByPropertyName=$true)]
    [string]
    $user,

    [parameter(Mandatory=$true,
      ValueFromPipelineByPropertyName=$true)]
    [string]
    $password
  )

  $secpasswd   = ConvertTo-SecureString $password -AsPlainText -Force
  $credentials = New-Object System.Management.Automation.PSCredential ($user, $secpasswd)
  return $credentials
}

$response = @{
  indesiredstate = $false
  rebootrequired = $false
  errormessage   = ''
}

$invokeParams = @{
  Name          = 'xWebAppPool'
  Method        = 'test'
  Property      = @{
    name = 'DefaultAppPool2'
    ensure = 'present'
    state = 'Started'
  }
  ModuleName = @{
    ModuleName      = "C:/ProgramData/PuppetLabs/code/environments/production/modules/dsc/lib/puppet_x/dsc_resources/xWebAdministration/xWebAdministration.psd1"
    RequiredVersion = "1.12.0.0"
  }
}

try{
    $result = Invoke-DscResource @invokeParams
}catch{
  $response.errormessage   = $_.Exception.Message
  return ($response | ConvertTo-Json -Compress)
}

# keep the switch for when Test passes back changed properties
switch ($invokeParams.Method) {
  'Test' {
    $response.indesiredstate = $result.InDesiredState
    return ($response | ConvertTo-Json -Compress)
  }
  'Set' {
    $response.indesiredstate = $true
    $response.rebootrequired = $result.RebootRequired
    return ($response | ConvertTo-Json -Compress)
  }
}
2016-09-23 06:56:01 -0500 Puppet (debug): 2016-09-23 06:56:01 -0500 C:\WINDOWS\system32\WindowsPowershell\v1.0\powershell.exe -NoProfile -NonInteractive -NoLogo -ExecutionPolicy Bypass -Command - is running as pid: 11888
2016-09-23 06:56:01 -0500 Puppet (debug): Waited 50 milliseconds...
2016-09-23 06:56:01 -0500 Puppet (debug): Waited 50 milliseconds...
STDOUT> At line:1 char:32
STDOUT> +         if ($runspace -eq $null)
STDOUT> +                                ~
STDOUT> Missing statement block after if ( condition ).
STDOUT>     + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
STDOUT>     + FullyQualifiedErrorId : MissingStatementBlock
STDOUT>  
STDOUT> 
STDOUT> 
STDOUT>           $runspace = [RunspaceFactory]::CreateRunspace()
STDOUT> 
STDOUT>           $runspace.Open()
STDOUT> 
STDOUT>         
STDOUT> At line:1 char:12
STDOUT> +         try
STDOUT> +            ~
STDOUT> The Try statement is missing its statement block.
STDOUT>     + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
STDOUT>     + FullyQualifiedErrorId : MissingTryStatementBlock
STDOUT>  
STDOUT> 
STDOUT> 
STDOUT>           # http://learn-powershell.net/2012/05/13/using-background-runspaces-instead-of-psjobs-for-better-performance/
STDOUT> 
STDOUT>           $ps = [powershell]::create()
STDOUT> 
STDOUT>           $ps.Runspace = $runspace
STDOUT> 
STDOUT>           [Void]$ps.AddScript($powershell_code)
STDOUT> 
STDOUT>           $asyncResult = $ps.BeginInvoke()
STDOUT> 
STDOUT>           if (!$asyncResult.AsyncWaitHandle.WaitOne(1200000))
STDOUT> 
STDOUT>           {
STDOUT> 
STDOUT>             throw "Catastrophic failure: PowerShell DSC resource timeout (1200000 ms) exceeded while executing"
STDOUT> 
STDOUT>           }
STDOUT> 
STDOUT>           $output = $ps.EndInvoke($asyncResult)
STDOUT> 
STDOUT>           Write-Output $output
STDOUT>        
STDOUT> catch : The term 'catch' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling 
STDOUT> of the name, or if a path was included, verify that the path is correct and try again.
STDOUT> At line:27 char:9
STDOUT> +         catch
STDOUT> +         ~~~~~
STDOUT>     + CategoryInfo          : ObjectNotFound: (catch:String) [], CommandNotFoundException
STDOUT>     + FullyQualifiedErrorId : CommandNotFoundException
STDOUT>  
STDOUT>           try
STDOUT> 
STDOUT>           {
STDOUT>             if ($runspace) { $runspace.Dispose() }
STDOUT>           }
STDOUT> 
STDOUT>           finally
STDOUT> 
STDOUT>           {
STDOUT>             $runspace = $null
STDOUT>           }
STDOUT> 
STDOUT>           @{
STDOUT> 
STDOUT>             indesiredstate = $false
STDOUT> 
STDOUT>             rebootrequired = $false
STDOUT> 
STDOUT>             errormessage = $_.Exception.Message
STDOUT> 
STDOUT>           } | ConvertTo-Json -Compress
STDOUT> 
STDOUT>         
STDOUT> finally : The term 'finally' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the 
STDOUT> spelling of the name, or if a path was included, verify that the path is correct and try again.
STDOUT> At line:59 char:9
STDOUT> +         finally
STDOUT> +         ~~~~~~~
STDOUT>     + CategoryInfo          : ObjectNotFound: (finally:String) [], CommandNotFoundException
STDOUT>     + FullyQualifiedErrorId : CommandNotFoundException
STDOUT>  
STDOUT> 
STDOUT> 
STDOUT>           [Void]$event.Set()
STDOUT> 
STDOUT>           [Void]$event.Dispose()
STDOUT> 
STDOUT>           if ($ps -ne $null) { [Void]$ps.Dispose() }
STDOUT> 
STDOUT>         
2016-09-23 06:56:02 -0500 Puppet (debug): Waited 50 milliseconds...
2016-09-23 06:56:02 -0500 Puppet (debug): Waited 50 milliseconds...
2016-09-23 06:56:02 -0500 Puppet (debug): Waited 50 milliseconds...
2016-09-23 06:56:02 -0500 Puppet (debug): Waited 50 milliseconds...
2016-09-23 06:56:02 -0500 Puppet (debug): Waited 50 milliseconds...
2016-09-23 06:56:02 -0500 Puppet (debug): Waited 50 milliseconds...
2016-09-23 06:56:03 -0500 Puppet (debug): Waited 50 milliseconds...
2016-09-23 06:56:03 -0500 Puppet (debug): Waited 50 milliseconds...
2016-09-23 06:56:03 -0500 Puppet (debug): Waited 50 milliseconds...
2016-09-23 06:56:03 -0500 Puppet (debug): Waited 50 milliseconds...
2016-09-23 06:56:03 -0500 Puppet (debug): Waited 50 milliseconds...

并且流程继续无限期地等待。

1 个答案:

答案 0 :(得分:0)

看起来它是 puppet powershell错误: https://tickets.puppetlabs.com/browse/MODULES-3690