可以使用Salt Cloud启动Windows实例,然后在其上安装Salt。 Salt Cloud支持的所有云提供商均提供此功能。 但是,它不一定在所有Windows映像上都可用。
注意:将停止对
winexe
和impacket
的支持,并在Sodium中删除。 这些依赖分别被pypsexec
和smbprotocol
取代。 这些是与所有受支持的python版本兼容的纯python实现的替代品。
Salt Cloud利用impacket和winexe来设置Windows Salt Minion安装程序。
impacket通常可以作为名为impacket或python-impacket软件包使用,具体取决于发行版。 有关impacket 的更多信息,请参见项目主页:
在特定于发行版的存储库中,winexe不太常见。 但是,目前正在为第三方渠道中的各种发行版本构建它:
如果可以使用python模块pywinrm并且目标Windows版本支持WinRM,则可以选择使用WinRM代替winexe。 可以在项目主页上找到有关pywinrm的信息:
此外,运行Salt Cloud的系统上必须存在Salt Minion Windows安装程序的副本。 可以从saltstack.com下载此安装程序:
Salt-Cloud可以使用pywinrm <= 0.1.1
或pywinrm> = 0.2.1
的版本。
对于大于0.2.1的版本,如果证书是自签名的且不可验证,则需要将winrm_verify_ssl
设置为False。
由于Salt Cloud使用smbclient和winexe,因此必须在目标镜像上打开端口445。 默认情况下,在标准Windows发行版中通常不会打开此端口,并且必须小心使用打开该端口或禁用Windows防火墙的镜像。
如果云提供商支持,则可以使用PowerShell脚本通过云提供商的用户数据自动打开此端口。 以下脚本将打开端口445,并应用更改:
<powershell>
New-NetFirewallRule -Name "SMB445" -DisplayName "SMB445" -Protocol TCP -LocalPort 445
Set-Item (dir wsman:\localhost\Listener\*\Port -Recurse).pspath 445 -Force
Restart-Service winrm
</powershell>
对于EC2,此脚本可以另存为文件,并在提provider程序或profile配置文件中指定为userdata_file
。 例如:
my-ec2-config:
# Pass userdata to the instance to be created
userdata_file: /etc/salt/windows-firewall.ps1
注意:从版本2016.11.0和2016.11.3起,此文件通过master的renderer传递以对其进行模板化。 但是,这会导致非YAML数据出现问题,因此默认情况下不再执行模板渲染。 要模板化userdata_file,请在云配置文件中添加一个
userdata_template
选项:my-ec2-config: # Pass userdata to the instance to be created userdata_file: /etc/salt/windows-firewall.ps1 userdata_template: jinja如果在云配置文件中未设置
userdata_template
,则将在master服务的配置中检查userdata_template
值。 如果未设置,则不会对userdata_file执行模板。要在master配置文件中设置userdata_template时需要先禁用云配置文件中的模板控制参数,只需在云配置文件中将
userdata_template
设置为False
即可:my-ec2-config: # Pass userdata to the instance to be created userdata_file: /etc/salt/windows-firewall.ps1 userdata_template: False
如果在EC2上使用WinRM,则还必须在userdata中启用WinRM服务的HTTPS端口。 默认情况下,EC2 Windows映像仅启用了不安全的HTTP。 要启用pywinrm所需的HTTPS和基本身份验证,请考虑以下userdata示例:
<powershell>
New-NetFirewallRule -Name "SMB445" -DisplayName "SMB445" -Protocol TCP -LocalPort 445
New-NetFirewallRule -Name "WINRM5986" -DisplayName "WINRM5986" -Protocol TCP -LocalPort 5986
winrm quickconfig -q
winrm set winrm/config/winrs '@{MaxMemoryPerShellMB="300"}'
winrm set winrm/config '@{MaxTimeoutms="1800000"}'
winrm set winrm/config/service/auth '@{Basic="true"}'
$SourceStoreScope = 'LocalMachine'
$SourceStorename = 'Remote Desktop'
$SourceStore = New-Object -TypeName System.Security.Cryptography.X509Certificates.X509Store -ArgumentList $SourceStorename, $SourceStoreScope
$SourceStore.Open([System.Security.Cryptography.X509Certificates.OpenFlags]::ReadOnly)
$cert = $SourceStore.Certificates | Where-Object -FilterScript {
$_.subject -like '*'
}
$DestStoreScope = 'LocalMachine'
$DestStoreName = 'My'
$DestStore = New-Object -TypeName System.Security.Cryptography.X509Certificates.X509Store -ArgumentList $DestStoreName, $DestStoreScope
$DestStore.Open([System.Security.Cryptography.X509Certificates.OpenFlags]::ReadWrite)
$DestStore.Add($cert)
$SourceStore.Close()
$DestStore.Close()
winrm create winrm/config/listener?Address=*+Transport=HTTPS `@`{CertificateThumbprint=`"($cert.Thumbprint)`"`}
Restart-Service winrm
</powershell>
默认情况下,EC2映像上没有可用的证书存储,并且没有MMC似乎无法创建证书存储(无法自动化)。 请将默认的EC2 Windows映像复制RDP存储后配置使用。
像往常一样设置配置,并进行一些额外的配置设置。 必须指定运行Salt Cloud的计算机上Windows安装程序的位置。 这可以在任何常规配置文件(master文件,provider程序,profile配置文件,map映射文件)中完成。 例如:
在/etc/salt/cloud.providers
中设置安装程序:
my-softlayer:
driver: softlayer
user: MYUSER1138
apikey: 'e3b68aa711e6deadc62d5b76355674beef7cc3116062ddbacafe5f7e465bfdc9'
minion:
master: saltmaster.example.com
win_installer: /root/Salt-Minion-2014.7.0-AMD64-Setup.exe
win_username: Administrator
win_password: letmein
smb_port: 445
默认的Windows用户是Administrator,默认的Windows密码是空。
如果要使用WinRM,则use_winrm
需要设置为True
。 winrm_port
可用于指定自定义端口(必须是HTTPS侦听器)。 可以将winrm_verify_ssl
设置为False
,以使用自签名证书。
在EC2上,当win_password设置为auto时,Salt Cloud将查询EC2以获取自动生成的密码。 该密码预计至少需要4分钟才能生成,从而为部署过程增加了额外的时间。
当查询EC2 API以获取自动生成的密码时,它将以使用指定键名加密的消息形式返回。 这要求还指定适当的private_key文件。 这样的配置文件配置可能如下所示:
windows-server-2012:
provider: my-ec2-config
image: ami-c49c0dac
size: m1.small
securitygroup: windows
keyname: mykey
private_key: /root/mykey.pem
userdata_file: /etc/salt/windows-firewall.ps1
win_installer: /root/Salt-Minion-2014.7.0-AMD64-Setup.exe
win_username: Administrator
win_password: auto