Powershell AWS Windows Server 2012R2 AMI+;用户数据运行
我的打包脚本如下所示:Powershell AWS Windows Server 2012R2 AMI+;用户数据运行,powershell,amazon-web-services,packer,Powershell,Amazon Web Services,Packer,我的打包脚本如下所示: { "description": "APLP GOLD IMAGE {{isotime \"20060102\"}}", "min_packer_version": "0.11.0", "variables": { "aws_region": "us-east-2", "aws_vpc": "xxxxxx", "aws_subnet": "xxxxxx" }, "builders":
{
"description": "APLP GOLD IMAGE {{isotime \"20060102\"}}",
"min_packer_version": "0.11.0",
"variables": {
"aws_region": "us-east-2",
"aws_vpc": "xxxxxx",
"aws_subnet": "xxxxxx"
},
"builders": [
{
"type": "amazon-ebs",
"profile": "nonprod",
"ami_name": "APLP (encrypted) {{isotime \"20060102\"}}",
"ami_description": "APLP Server2012R2 x86_64 HVM EBS (encrypted) {{isotime \"20060102\"}}",
"instance_type": "t2.micro",
"region": "{{user `aws_region`}}",
"vpc_id": "{{user `aws_vpc`}}",
"subnet_id": "{{user `aws_subnet`}}",
"source_ami_filter": {
"filters": {
"name": "Windows_Server-2012-R2_RTM-English-64Bit-Base-*",
"virtualization-type": "hvm"
},
"owners": ["801119661308"],
"most_recent": true
},
"communicator": "winrm",
"user_data_file":"./SetUpWinRM.ps1",
"winrm_username": "Administrator",
"winrm_use_ssl": true,
"winrm_insecure": true,
"ami_virtualization_type": "hvm",
"tags": {
"Name": "APLP Server2012R2 Gold",
"OS": "Windows Server",
"OSVER": "2012R2"
},
"encrypt_boot": true,
"launch_block_device_mappings": [
{
"device_name": "/dev/sda1",
"volume_size": 100,
"volume_type": "gp2",
"delete_on_termination": true
}
]
}
],
"provisioners": [
{
"type": "powershell",
"scripts": [
"sysprep.ps1",
"ec2config.ps1",
"defrag.ps1",
"disableuac.ps1"
]
}
]
}
我在构建中的用户数据只是配置了WINRM,它已经在线显示了好几个地方,效果非常好。我还有几个运行的powershell Provisioner任务,特别是在上运行的:
$EC2SettingsFile = "C:\\Program Files\\Amazon\\Ec2ConfigService\\Settings\\Config.xml"
$xml = [xml](get-content $EC2SettingsFile)
$xmlElement = $xml.get_DocumentElement()
$xmlElementToModify = $xmlElement.Plugins
foreach ($element in
$xmlElementToModify.Plugin) {
if ($element.name -eq
"Ec2SetPassword") {
$element.State = "Enabled"
}
elseif ($element.name -eq
"Ec2SetComputerName") {
$element.State = "Enabled"
}
elseif ($element.name -eq
"Ec2HandleUserData") {
$element.State = "Enabled"
}
elseif ($element.name -eq
"Ec2DynamicBootVolumeSize") {
$element.State = "Enabled"
}
}
$xml.Save($EC2SettingsFile)
创建映像后,我甚至从快照创建了一个卷,以确保Config.xml当前配置为运行userdata。我遇到的问题是,userdata从未运行过与我使用packer的AMI构建的新实例相关的数据。如果我使用AWS clean AMI,则我的userdata运行良好,而当我使用自定义AMI运行相同的用户数据时,则不会
我的理解是,我在configservice中更改config.xml的原因是为了让userdata再运行一次。在部署AMI后,我还可以在windows中调出ec2config UI,并单击启动时运行userdata,一切都会按预期运行
非常感谢您的帮助 你解决了这个问题吗?我也有同样的问题,你解决了吗?我也有同样的问题。