gpt4 book ai didi

amazon-ec2 - 使用 cloudformation 堆栈在带有 ansible 的自动缩放组中配置 ec2

转载 作者:行者123 更新时间:2023-12-03 07:28:30 24 4
gpt4 key购买 nike

我创建了自动扩展组,该组启动具有 ELB 的 EC2。我的问题是如何使用 ansible 配置这些 EC2 实例?之前我使用CNAME,但现在我无法获取实例dns。如果我错了,请纠正我。

我应该使用动态库存还是还有其他选择?

下面是我的云形成模板:

```

{
"AWSTemplateFormatVersion" : "2010-09-09",
"Description" : "Template create autoscaling group",
"Parameters": {
"devKeyPair": {
"Description": "Name of an existing EC2 KeyPair to enable SSH access to the instances",
"Type": "AWS::EC2::KeyPair::KeyName",
"Default" : "dev-key"

}
},
"Resources" : {
"LaunchConfig" : {
"Type" : "AWS::AutoScaling::LaunchConfiguration",
"Properties" : {
"KeyName" : { "Ref": "devKeyPair" },
"ImageId" : "ami-1effc703",
"UserData" : { "Fn::Base64" : { "Fn::Join" : ["", [
"#!/bin/bash\n", "\n", " echo 'Installing Git'\n"," yum --nogpgcheck -y install wget\n""] ]}},
"InstanceType" : "t2.small",
"BlockDeviceMappings" : [
{
"DeviceName" : "/dev/sda1",
"Ebs" : {
"VolumeSize" : "10",
"VolumeType" : "gp2",
"DeleteOnTermination" : "true"
}
}
]
}
},
"BackendGroup" : {
"Type" : "AWS::AutoScaling::AutoScalingGroup",
"Properties" : {
"AvailabilityZones" : ["eu-central-1a"],
"MinSize" : "1",
"MaxSize" : "1",
"LaunchConfigurationName" : { "Ref" : "LaunchConfig" },
"LoadBalancerNames" : [ { "Ref" : "ElasticLoadBalancer" } ],
"Tags": [
{
"ResourceType": "auto-scaling-group",
"ResourceId": "bas-auto",
"Value": "bas-dev",
"Key": "Name",
"PropagateAtLaunch" : "true"
}
]
}
},

"ElasticLoadBalancer": {
"Type": "AWS::ElasticLoadBalancing::LoadBalancer",
"Properties": {
"AvailabilityZones": ["eu-central-1a"],
"Listeners": [ {
"LoadBalancerPort": "80",
"InstancePort": "80",
"Protocol": "HTTP"
} ]
}
},
"BackendDNS" : {
"Type" : "AWS::Route53::RecordSetGroup",
"Properties" : {
"HostedZoneName" : "example.com.",
"Comment" : "Targered to Bas instance",
"RecordSets" : [{
"Name" : "bas-dev.example.com.",
"Type" : "CNAME",
"TTL" : "300",
"ResourceRecords" : [
{
"Fn::GetAtt": [ "ElasticLoadBalancer", "DNSName" ]
}
]
}]
}
},
}
}

```

最佳答案

另一个解决方案是在启动新实例之前配置您的虚拟机。 IE。确保您启动 ASG 实例的镜像已配置。一种方法是使用类似 packer.io 的内容。使用 Ansible 作为您的配置程序来创建新的 AMI。然后,您只需将此新的 AMI ID 传递到 LaunchConfiguration 的 ImageId 属性中即可。

另一种方法可能涉及使用用户数据“打电话回家”并告诉您实例已获取的公共(public) IP 地址。

关于amazon-ec2 - 使用 cloudformation 堆栈在带有 ansible 的自动缩放组中配置 ec2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36470865/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com