我对这个ansible playbook的目标是根据已经运行的内容启动8个ec2实例。我在查找信息时遇到问题的部分是按顺序命名/标记实例。有没有办法让tag_Name成为ansible-test-1到8?
以下是我所拥有的:
- name: Provision EC2 instances
ec2:
key_name: "{{ aws_public_key }}"
instance_type: t2.small
image: "{{ aws_ubuntu_ami }}"
wait: true
vpc_subnet_id: "{{ dev_subnet_public }}"
group_id: "{{ aws_group }}"
assign_public_ip: yes
instance_tags:
Name: ansible-test
environment: qa
exact_count: 8
count_tag:
Name: ansible-test*
region: "{{ aws_region }}"
volumes:
- device_name: /dev/sda1
volume_size: 300
register: ec2
答案 0 :(得分:0)
试试这个:
- name: Provision EC2 instances
ec2:
key_name: "{{ aws_public_key }}"
instance_type: t2.small
image: "{{ aws_ubuntu_ami }}"
wait: true
vpc_subnet_id: "{{ dev_subnet_public }}"
group_id: "{{ aws_group }}"
assign_public_ip: yes
instance_tags:
Name: ansible-test-{{item}}
environment: qa
count: 1
region: "{{ aws_region }}"
volumes:
- device_name: /dev/sda1
volume_size: 300
register: ec2
with_items:
- 1
- 2
.....
- 8
另一种方法是使用ec2_tag
答案 1 :(得分:0)
使用with_sequence
示例:
- name: Provision EC2 instances
ec2:
key_name: "{{ aws_public_key }}"
instance_type: t2.small
image: "{{ aws_ubuntu_ami }}"
wait: true
vpc_subnet_id: "{{ dev_subnet_public }}"
group_id: "{{ aws_group }}"
assign_public_ip: yes
instance_tags:
Name: ansible-test-{{item}}
environment: qa
with_sequence:
count: 8
exact_count: 8
count_tag:
Name: ansible-test*
region: "{{ aws_region }}"
volumes:
- device_name: /dev/sda1
volume_size: 300
register: ec2