Chef infra 使用Chef启用IIS
试着自学Powershell和Chef,所以我肯定我错过了一些简单的东西 所以我实际上使用了一个名为Chef的服务器管理程序。但是脚本使用PS解释器运行。我确保ServerManager模块已导入,我正在使用Admin priv运行PS,并且我正在运行64位版本的PS 这是我启用IIS的脚本(如果还没有)Chef infra 使用Chef启用IIS,chef-infra,Chef Infra,试着自学Powershell和Chef,所以我肯定我错过了一些简单的东西 所以我实际上使用了一个名为Chef的服务器管理程序。但是脚本使用PS解释器运行。我确保ServerManager模块已导入,我正在使用Admin priv运行PS,并且我正在运行64位版本的PS 这是我启用IIS的脚本(如果还没有) powershell_script 'Install IIS' do code 'Add-WindowsFeature Web-Server' guard_interpreter :p
powershell_script 'Install IIS' do
code 'Add-WindowsFeature Web-Server'
guard_interpreter :powershell_script
not_if "(Get-WindowsFeature -Name Web-Server).Installed"
end
运行时,我收到以下错误消息:
PS C:\Users\Administrator\chef-repo> chef-apply .\webserver.rb
Recipe: (chef-apply cookbook)::(chef-apply recipe)
* powershell_script[Install IIS] action run
================================================================================
Error executing action `run` on resource 'powershell_script[Install IIS]'
================================================================================
Mixlib::ShellOut::ShellCommandFailed
------------------------------------
Expected process to exit with [0], but received '1'
---- Begin output of "powershell.exe" -NoLogo -NonInteractive -NoProfile -ExecutionPolicy RemoteSigned -InputFormat
None -File "C:/Users/ADMINI~1/AppData/Local/Temp/chef-script20141224-1308-ftog62.ps1" ----
STDOUT:
STDERR: The term 'Add-WindowsFeature' is not recognized as the name of a cmdlet, function, script file, or operable
program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
---- End output of "powershell.exe" -NoLogo -NonInteractive -NoProfile -ExecutionPolicy RemoteSigned -InputFormat No
ne -File "C:/Users/ADMINI~1/AppData/Local/Temp/chef-script20141224-1308-ftog62.ps1" ----
Ran "powershell.exe" -NoLogo -NonInteractive -NoProfile -ExecutionPolicy RemoteSigned -InputFormat None -File "C:/Us
ers/ADMINI~1/AppData/Local/Temp/chef-script20141224-1308-ftog62.ps1" returned 1
Resource Declaration:
---------------------
# In .\webserver.rb
1: powershell_script 'Install IIS' do
2: code 'Add-WindowsFeature Web-Server'
3: guard_interpreter :powershell_script
4: not_if "(Get-WindowsFeature -Name Web-Server).Installed"
5: end
Compiled Resource:
------------------
# Declared in .\webserver.rb:1:in `run_chef_recipe'
powershell_script("Install IIS") do
action "run"
retries 0
retry_delay 2
guard_interpreter :powershell_script
command "\"powershell.exe\" -NoLogo -NonInteractive -NoProfile -ExecutionPolicy RemoteSigned -InputFormat None -File \"C:/Users/ADMINI~1/AppData/Local/Temp/chef-script20141224-1308-ftog62.ps1\""
backup 5
returns 0
code "Add-WindowsFeature Web-Server"
interpreter "powershell.exe"
cookbook_name "(chef-apply cookbook)"
recipe_name "(chef-apply recipe)"
not_if "(Get-WindowsFeature -Name Web-Server).Installed"
end
[2014-12-24T09:37:19-08:00] FATAL: Stacktrace dumped to C:/chef/cache/chef-stacktrace.out
[2014-12-24T09:37:19-08:00] FATAL: Mixlib::ShellOut::ShellCommandFailed: powershell_script[Install IIS] ((chef-apply coo
kbook)::(chef-apply recipe) line 1) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0
], but received '1'
---- Begin output of "powershell.exe" -NoLogo -NonInteractive -NoProfile -ExecutionPolicy RemoteSigned -InputFormat None
-File "C:/Users/ADMINI~1/AppData/Local/Temp/chef-script20141224-1308-ftog62.ps1" ----
STDOUT:
STDERR: The term 'Add-WindowsFeature' is not recognized as the name of a cmdlet, function, script file, or operable prog
ram. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
---- End output of "powershell.exe" -NoLogo -NonInteractive -NoProfile -ExecutionPolicy RemoteSigned -InputFormat None -
File "C:/Users/ADMINI~1/AppData/Local/Temp/chef-script20141224-1308-ftog62.ps1" ----
Ran "powershell.exe" -NoLogo -NonInteractive -NoProfile -ExecutionPolicy RemoteSigned -InputFormat None -File "C:/Users/
ADMINI~1/AppData/Local/Temp/chef-script20141224-1308-ftog62.ps1" returned 1
这可以通过使用
windows\u功能
(内置于chef中)来实现,因为这并不是您认为的真正的机会:
配方: 列表中列出了我正在启用的所有功能…您可以只执行一项功能,如下所示:
windows_feature 'IIS-WebServerRole' do
action :install
end
但是上面的内容并不是IIS所需要的全部内容。。。
您可以在此处找到非常具体的信息:这可以使用
windows\u功能(内置到chef中)来完成,因为这不是您认为的真正的机会:
配方:
列表中列出了我正在启用的所有功能…您可以只执行一项功能,如下所示:
windows_feature 'IIS-WebServerRole' do
action :install
end
但是上面的内容并不是IIS所需要的全部内容。。。
您可以在这里找到非常具体的信息:对于那些试图学习厨师基础教程并被此错误困扰的人-
本教程似乎假设您有PowerShell 3.0,在那里,模块在需要时自动导入。PowerShell 2.0的情况并非如此,您必须在烹饪书中明确导入它们
首先,通过运行$psversiontable
确保您正在运行PowerShell 2.0
PS C:\Users\Administrator\chef-repo> $psversiontable
Name Value
---- -----
CLRVersion 2.0.50727.5477
BuildVersion 6.1.7601.17514
PSVersion 2.0
WSManStackVersion 2.0
PSCompatibleVersions {1.0, 2.0}
SerializationVersion 1.1.0.1
PSRemotingProtocolVersion 2.1
请注意PSVersion
的值-如果它不是2.0
,则可能存在其他问题
以下是导入右模块的更新脚本:
powershell_script 'Install IIS' do
code <<-EOH
Import-Module ServerManager
Add-WindowsFeature Web-Server
EOH
guard_interpreter :powershell_script
not_if "Import-Module ServerManager; (Get-WindowsFeature -Name Web-Server).Installed"
end
powershell\u脚本“安装IIS”执行
代码对于那些试图通过厨师基础教程并被此错误困扰的人-
本教程似乎假设您有PowerShell 3.0,在那里,模块在需要时自动导入。PowerShell 2.0的情况并非如此,您必须在烹饪书中明确导入它们
首先,通过运行$psversiontable
确保您正在运行PowerShell 2.0
PS C:\Users\Administrator\chef-repo> $psversiontable
Name Value
---- -----
CLRVersion 2.0.50727.5477
BuildVersion 6.1.7601.17514
PSVersion 2.0
WSManStackVersion 2.0
PSCompatibleVersions {1.0, 2.0}
SerializationVersion 1.1.0.1
PSRemotingProtocolVersion 2.1
请注意PSVersion
的值-如果它不是2.0
,则可能存在其他问题
以下是导入右模块的更新脚本:
powershell_script 'Install IIS' do
code <<-EOH
Import-Module ServerManager
Add-WindowsFeature Web-Server
EOH
guard_interpreter :powershell_script
not_if "Import-Module ServerManager; (Get-WindowsFeature -Name Web-Server).Installed"
end
powershell\u脚本“安装IIS”执行
如果你需要比我在下面提供的更多的帮助,请告诉我代码。如果你需要比我在下面提供的更多的帮助,请告诉我。只需补充一点……在PS4.0版本中,我也有同样的问题——这很有效!我不需要在not_if块中添加import语句…只需要代码块就可以添加…对于PS4.0版本,我也有同样的问题-这很有效!我不需要在not_if块中添加import语句,只需要在代码块中添加