Actually, I just played with this a bit more and registered the output of 
the EC2 task that creates these instances. I've run through this a number 
of times so the 1 instance already exists, but the output of my Ansible run 
indicates that it thinks there are 2 instances. The following is the 
registered output:

ok: [localhost] => {
    "var": {
        "app_var": {
            "changed": false,
            "msg": "All items completed",
            "results": [
                {
                    "changed": false,
                    "skipped": true
                },
                {
                    "changed": false,
                    "instance_ids": null,
                    "instances": [],
                    "invocation": {
                        "module_args": "",
                        "module_name": "ec2"
                    },
                    "item": {
                        "az": "us-west-1a",
                        "cidr": "10.1.2.0/24",
                        "id": "subnet-ecea39b5",
                        "resource_tags": {
                            "Name": "example-subnet-app"
                        }
                    },
                    "tagged_instances": [
                        {
                            "ami_launch_index": "0",
                            "architecture": "x86_64",
                            "dns_name": "",
                            "ebs_optimized": false,
                            "groups": {
                                "sg-3684fe53": "example-sg-app",
                                "sg-3c84fe59": "example-sg-access"
                            },
                            "hypervisor": "xen",
                            "id": "i-cb3fe479",
                            "image_id": "ami-df6a8b9b",
                            "instance_type": "c4.large",
                            "kernel": null,
                            "key_name": "example_key",
                            "launch_time": "2015-09-28T22:39:11.000Z",
                            "placement": "us-west-1a",
                            "private_dns_name": 
"ip-10-1-2-63.us-west-1.compute.internal",
                            "private_ip": "10.1.2.63",
                            "public_dns_name": "",
                            "public_ip": null,
                            "ramdisk": null,
                            "region": "us-west-1",
                            "root_device_name": "/dev/sda1",
                            "root_device_type": "ebs",
                            "state": "running",
                            "state_code": 16,
                            "tags": {
                                "Environment": "prod",
                                "Name": "example-ec2-app",
                                "Subnet": "example-subnet-app",
                                "Type": "app",
                                "VPC": "example"
                            },
                            "tenancy": "default",
                            "virtualization_type": "hvm"
                        }
                    ]
                },
                {
                    "changed": false,
                    "instance_ids": null,
                    "instances": [],
                    "invocation": {
                        "module_args": "",
                        "module_name": "ec2"
                    },
                    "item": {
                        "az": "us-west-1b",
                        "cidr": "10.1.3.0/24",
                        "id": "subnet-921486f7",
                        "resource_tags": {
                            "Name": "example-subnet-app"
                        }
                    },
                    "tagged_instances": [
                        {
                            "ami_launch_index": "0",
                            "architecture": "x86_64",
                            "dns_name": "",
                            "ebs_optimized": false,
                            "groups": {
                                "sg-3684fe53": "example-sg-app",
                                "sg-3c84fe59": "example-sg-access"
                            },
                            "hypervisor": "xen",
                            "id": "i-cb3fe479",
                            "image_id": "ami-df6a8b9b",
                            "instance_type": "c4.large",
                            "kernel": null,
                            "key_name": "example_key",
                            "launch_time": "2015-09-28T22:39:11.000Z",
                            "placement": "us-west-1a",
                            "private_dns_name": 
"ip-10-1-2-63.us-west-1.compute.internal",
                            "private_ip": "10.1.2.63",
                            "public_dns_name": "",
                            "public_ip": null,
                            "ramdisk": null,
                            "region": "us-west-1",
                            "root_device_name": "/dev/sda1",
                            "root_device_type": "ebs",
                            "state": "running",
                            "state_code": 16,
                            "tags": {
                                "Environment": "prod",
                                "Name": "example-ec2-app",
                                "Subnet": "example-subnet-app",
                                "Type": "app",
                                "VPC": "example"
                            },
                            "tenancy": "default",
                            "virtualization_type": "hvm"
                        }
                    ]
                },
                {
                    "changed": false,
                    "skipped": true
                },
                {
                    "changed": false,
                    "skipped": true
                },
                {
                    "changed": false,
                    "skipped": true
                },
                {
                    "changed": false,
                    "skipped": true
                },
                {
                    "changed": false,
                    "skipped": true
                },
                {
                    "changed": false,
                    "skipped": true
                },
                {
                    "changed": false,
                    "skipped": true
                }
            ]
        }
    }
}

It appears to me that Ansible thinks 2 instances exist, but I only see one 
in the AWS console.

On Thursday, October 8, 2015 at 11:23:50 AM UTC-7, Guy Knights wrote:
>
> I have a playbook that fires up some ec2 instances in multiple subnets 
> using exact_count and count_tag to control how many instances are created. 
> I'm using when to loop over the subnets I want to use - in this particular 
> case, there are 2 subnets in different availability zones, and I want to 
> create one instance in each AZ.
>
> The problem is that if I set exact_count to 1, ansible creates the first 
> instance and then doesn't create the second instance in the second subnet 
> as exact_count is already reached. If I change exact_count to 2, it will 
> create 2 instances but they're in the same subnet. Basically, the loop is 
> irrelevant.
>
> Is there any way around this issue?
>
> Thanks,
> Guy
>

-- 
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 ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/cbcdf00e-1979-41b3-9a81-147dedf45df0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to