午餐ec2实例时,我无法从ansible迁移到terrafrom。 使用ansible,您可以在清单文件中定义一组服务器
[GRAYLOG_SERVERS]
graylog-master ansible_host=1.1.1.1 disk_size=50 instance_type=t2.small
graylog-slave ansible-host=1.1.1.2 disk_size=50 instance_type=t2.small
[GRAYLOG_SERVERS:vars]
var=foo
elb=bla
并通过ec2模块示例为您的实例加餐:
- name: lunching instance
ec2:
aws_access_key: "{{ access_key }}"
aws_secret_key: "{{ secret_key }}"
key_name: "{{ ec2_keypair }}"
group_id: "{{ target_security_groups }}"
instance_type: "{{ instance_type }}"
image: "{{ target_ami }}"
vpc_subnet_id: "{{ instance_subnet_id }}"
region: "{{ aws_region }}"
instance_tags: '{"Name":"{{ec2_tag_Name}}","Product":"{{ec2_tag_Product}}","Environment":"{{ec2_tag_Environment}}"}'
private_ip: "{{ ansible_host }}"
exact_count: 1
count_tag: '{"Name":"{{ec2_tag_Name}}","Product":"{{ec2_tag_Product}}","Environment":"{{ec2_tag_Environment}}"}'
assign_public_ip: no
wait: true
volumes:
- device_name: "{{ device_name }}"
device_type: "{{ device_type }}"
volume_size: "{{ disk_size }}"
delete_on_termination: true
delegate_to: localhost
when: ec2_image is defined or ami_id is defined
register: ec2
我可以基于服务器组和其他选项(例如每组添加--limit
)创建实例计数
这样的操作可以与Terraform复制吗?