Ansible生成带有增量编号

时间:2017-02-09 19:58:50

标签: amazon-web-services amazon-ec2 ansible

我试图使用带有标签的ansible来启动N个ec2实例:名称如" nginx1,nginx2"根据N个实例,我很确定有办法,但我不知道如何

 - name: Nginx Nodes
   ec2:
    key_name: "{{ key_name }}"
    region: "{{ region }}"
    instance_type: t2.nano
    image: "{{ nginx_ami }}"
    group: nginxsg
    exact_count: 2
    count_tag: 
      Name: "{{ nginx_name }}"
    instance_tags:
       Name: "{{ nginx_name }}"
       Environment: "{{ env }}"
    monitoring: no
    vpc_subnet_id: "{{ AWS.db_subnets | random }}"
    assign_public_ip: yes
  register: nignx_instance

1 个答案:

答案 0 :(得分:0)

可能是这样的,根据您的要求调整此示例。

- name: Nginx Nodes
   ec2:
    key_name: "{{ key_name }}"
    region: "{{ region }}"
    instance_type: t2.nano
    image: "{{ nginx_ami }}"
    group: nginxsg
    instance_tags:
       Name: "{{ nginx_name }}-{{ item.0 + 1 }}"
       Environment: "{{ env }}"
    monitoring: no
    vpc_subnet_id: "{{ item.1 }}"
    assign_public_ip: yes
  with_indexed_items: "{{ AWS.db_subnets }}"
  register: nignx_instance

如需完整参考,请参阅此link