【发布时间】:2017-09-30 03:07:15
【问题描述】:
我正在尝试使用 Packer 构建 Windows AMI(自定义 AWS 映像)。 有没有办法在 macOS 上使用 WinRM,还是我必须在 windows 机器上构建映像?
我们混合使用 Ubuntu 和 Windows 服务器,其中大多数是 Ubuntu 服务器。我想在我的macbook上构建它。在生产中,我们使用 Jenkins。
映像的目的是运行 IIS 和 Sitecore。
我需要安装
- IIS
- 网站核心
- 文件节拍
代码示例:
resource "aws_key_pair" "mykey" {
key_name = "mykey"
public_key = "${file("${var.PATH_TO_PUBLIC_KEY}")}"
}
resource "aws_instance" "win-example" {
security_groups = [ "${aws_security_group.windows-admin.id}" ]
subnet_id = "subnet-730c9c16"
ami = "ami-40003a26"
instance_type = "t2.micro"
associate_public_ip_address = true
key_name = "${aws_key_pair.mykey.key_name}"
tags {
Name = "win-example"
}
user_data = <<EOF
<powershell>
net user ${var.INSTANCE_USERNAME} ${var.INSTANCE_PASSWORD} /add
net localgroup administrators ${var.INSTANCE_USERNAME} /add
winrm quickconfig -q
winrm set winrm/config/winrs '@{MaxMemoryPerShellMB="300"}'
winrm set winrm/config '@{MaxTimeoutms="1800000"}'
winrm set winrm/config/service '@{AllowUnencrypted="true"}'
winrm set winrm/config/service/auth '@{Basic="true"}'
netsh advfirewall firewall add rule name="WinRM 5985" protocol=TCP dir=in localport=5985 action=allow
netsh advfirewall firewall add rule name="WinRM 5986" protocol=TCP dir=in localport=5986 action=allow
net stop winrm
sc.exe config winrm start=auto
net start winrm
</powershell>
EOF
provisioner "file" {
source = "test.txt"
destination = "C:/test.txt"
connection {
type = "winrm"
user = "${var.INSTANCE_USERNAME}"
password = "${var.INSTANCE_PASSWORD}"
insecure = true
timeout = "10m"
}
}
connection {
type = "winrm"
user = "${var.INSTANCE_USERNAME}"
password = "${var.INSTANCE_PASSWORD}"
insecure = true
timeout = "10m"
}
}
terraform 报错:
Error applying plan:
1 error(s) occurred:
* aws_instance.win-example: 1 error(s) occurred:
* unknown error Post http://54.229.229.22:5985/wsman: dial tcp 54.229.229.22:5985: getsockopt: operation timed out
powershell 脚本运行并创建用户,但文件“test.txt”并未复制到服务器。
【问题讨论】:
标签: amazon-web-services amazon-ami packer