Thank you. This works great. On Monday, January 24, 2022 at 12:51:24 AM UTC-8 [email protected] wrote:
> Hii > > > On Sun, 23 Jan 2022 at 16:01, Tony Wong <[email protected]> wrote: > > > > I am just trying to create 2 or more ec2 instances. > > Here you say 2 > > > >>> - name: create the ec2 instance > >>> ec2: > >>> assign_public_ip: no > >>> group_id: '{{ deploy_env.sg_group }}' > >>> instance_type: "{{ deploy_env.instance_type }}" > >>> image: "{{ deploy_env.image }}" > >>> wait: true > >>> wait_timeout: 600 > >>> count: 10 > > But here it says 10 are created. > > https://docs.ansible.com/ansible/latest/collections/amazon/aws/ec2_module.html#parameter-count > > Assuming this is an oversight, this should work: > > - include_vars: vars/main.yml > > - name: create the ec2 instance > > ec2: > > assign_public_ip: no > > group_id: '{{ deploy_env.sg_group }}' > > instance_type: "{{ deploy_env.instance_type }}" > > image: "{{ deploy_env.image }}" > > wait: true > > wait_timeout: 600 > > count: 1 > > region: "{{ deploy_env.region }}" > > vpc_subnet_id: "{{ deploy_env.vpc_subnet_id}}" > > private_ip: "{{ item.ip }}" > > instance_tags: > > Name: "{{ item.name }}" > > loop: "{{ instances }}" > > > > And then in your vars file: > > deploy_env: > > instance_type: t2.micro > > image: ami-02d03ce209db75523 > > sg_group: > > - "sg-057771872265bfda6" > > region: us-west-1 > > vpc_subnet_id: subnet-0d9d37440a2265163 > > > > instances: > > - name: test1 > > ip: 10.10.1.10 > > - name: test2 > > ip: 10.10.1.12 > > - name: test43 > > ip: 10.10.1.77 > > > > -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/3bbfe10d-61a4-4994-902f-56e117e218afn%40googlegroups.com.
