Issue 1:
ISSUE TYPE

Bug Report

COMPONENT NAME

ec2_asg

ANSIBLE VERSION

ansible 2.4.3.0
config file = /home/admin/.ansible.cfg
configured module search path = [u'/home/admin/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/local/lib/python2.7/dist-packages/ansible
executable location = /usr/local/bin/ansible
python version = 2.7.9 (default, Jun 29 2016, 13:08:31) [GCC 4.9.2]

CONFIGURATION

N/A

OS / ENVIRONMENT

Debian Jessie

SUMMARY

When I use ec2_asg to replace a single instance in an existing ASG, the old instance is terminated before a new one is created. This would be fine except that ec2_asg has classically worked by increasing the capacity of the ASG by 1 to first create a new instance. So now you get two new instances, and when ec2_asg scales the capacity back, you're at the mercy of the termination policy.

STEPS TO REPRODUCE

In my case I was working with an ASG with 3 instances. I suspect this will work with any number of instances though.

Assuming you have an AWS region, ASG, LC, and instance ID in mind:

- ec2_asg:
lc_check: no
replace_batch_size: 1
replace_instances: "{{ instance_to_cycle }}"
name: "{{ asg_name }}"
min_size: "3"
max_size: "3"
desired_capacity: "3"
launch_config_name: "{{ lc_name }}"
region: "{{ region }}"
wait_timeout: 480
register: ec2_asg_result

EXPECTED RESULTS

The ASG's min, max, and desired counts will all raise by 1. A new instance will start to be created. Once that happens, then the min/desired counts will decrease so an old instance will be terminated.

ACTUAL RESULTS

An instance is terminated before a new instance is created. (I determined this just by repeatedly hitting the refresh button on the AWS console.)

Using debug on the result you can see that ec2_asg_result.instances has 4 IDs in it it.

I tried downgrading to 2.1.2.0 and did not see this behavior. Never mind, I see this on that version too, it's just not consistent.

Issue 2:
ISSUE TYPE

Bug Report

COMPONENT NAME

docker_container

ANSIBLE VERSION

ansible 2.4.0.0
config file = /etc/ansible/ansible.cfg
configured module search path = [u'/home/user/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /home/user/.local/lib/python2.7/site-packages/ansible
executable location = /usr/bin/ansible
python version = 2.7.13 (default, Sep 5 2017, 08:53:59) [GCC 7.1.1 20170622 (Red Hat 7.1.1-3)]

CONFIGURATION

OS / ENVIRONMENT

N/A

SUMMARY

Containers get restarted/recreated on every run, even though nothing changed. No idempotency.

STEPS TO REPRODUCE

- name: setup registry container
docker_container:
name: registry
hostname: dockerhub.example.com
state: started
restart_policy: always
image: registry:2
ports:
- 5000:5000
volumes:
- "{{ docker_container_certs_path }}:/certs"
env:
REGISTRY_HTTP_TLS_CERTIFICATE: /certs/dockerhub.example.com.crt
REGISTRY_HTTP_TLS_KEY: /certs/dockerhub.example.com.key

- name: setup registry frontend container
docker_container:
name: registry-frontend
hostname: registry-frontend
state: started
restart_policy: always
image: konradkleine/docker-registry-frontend:v2
links: registry:registry
ports:
- 443:443
volumes:
- "{{ docker_container_certs_path }}/{{ docker_registry_hostname }}.crt:/etc/apache2/server.crt:ro"
- "{{ docker_container_certs_path }}/{{ docker_registry_hostname }}.key:/etc/apache2/server.key:ro"
env:
ENV_DOCKER_REGISTRY_HOST: registry
ENV_DOCKER_REGISTRY_PORT: 5000
ENV_USE_SSL: yes
ENV_DOCKER_REGISTRY_USE_SSL: 1
FRONTEND_BROWSE_ONLY_MODE: false
ENV_REGISTRY_PROXY_FQDN: dockerhub.example.com
ENV_REGISTRY_PROXY_PORT: 443

EXPECTED RESULTS

Expected to leave the running containers untouched when no parameters change.

ACTUAL RESULTS

On every subsequent run:

[.....]
TASK [docker : setup registry container] ***************************************
changed: [foobar]

TASK [docker : setup registry frontend container] ******************************
changed: [foobar]

PLAY RECAP *********************************************************************
foobar : ok=16 changed=2 unreachable=0 failed=0

Also molecule reports those tasks as problematic:

$ molecule idempotence
--> Test matrix

└── default
└── idempotence
--> Scenario: 'default'
--> Action: 'idempotence'
ERROR: Idempotence test failed because of the following tasks:
* [foobar] => docker : setup registry container
* [foobar] => docker : setup registry frontend container

A docker inspect diff of two subsequent runs:

$ diff run1.txt run2.txt
3,4c3,4
< "Id": "7a9675ad0b9dd40106a954856be32b57c30081eea7f16c94e77bc402bdba02bf",
< "Created": "2017-10-05T16:38:40.543640249Z",
---
> "Id": "b256cce8eb8fb26f30270a837bb3e38cd382a20dc402b0dfe6bd0b05d984db02",
> "Created": "2017-10-05T19:32:24.871726187Z",
15c15
< "Pid": 25641,
---
> "Pid": 29287,
18c18
< "StartedAt": "2017-10-05T16:38:40.978651324Z",
---
> "StartedAt": "2017-10-05T19:32:25.373263113Z",
24c24
< "EndpointID": "0c0f5324afb22441171205f6efa28f05d45d01b1ae9416c2e90696b39e9f33f0",
---
> "EndpointID": "21a4fc8f9688e8ac3b2586abf5252343a05659e60a4e970002ed30f53c05e23f",
29c29
< "IPAddress": "172.17.0.19",
---
> "IPAddress": "172.17.0.21",
34c34
< "MacAddress": "02:42:ac:11:00:13",
---
> "MacAddress": "02:42:ac:11:00:15",
45c45
< "SandboxKey": "/var/run/docker/netns/7a9675ad0b9d",
---
> "SandboxKey": "/var/run/docker/netns/b256cce8eb8f",
49,52c49,52
< "ResolvConfPath": "/var/lib/docker/containers/7a9675ad0b9dd40106a954856be32b57c30081eea7f16c94e77bc402bdba02bf/resolv.conf",
< "HostnamePath": "/var/lib/docker/containers/7a9675ad0b9dd40106a954856be32b57c30081eea7f16c94e77bc402bdba02bf/hostname",
< "HostsPath": "/var/lib/docker/containers/7a9675ad0b9dd40106a954856be32b57c30081eea7f16c94e77bc402bdba02bf/hosts",
< "LogPath": "/var/lib/docker/containers/7a9675ad0b9dd40106a954856be32b57c30081eea7f16c94e77bc402bdba02bf/7a9675ad0b9dd40106a954856be32b57c30081eea7f16c94e77bc402bdba02bf-json.log",
---
> "ResolvConfPath": "/var/lib/docker/containers/b256cce8eb8fb26f30270a837bb3e38cd382a20dc402b0dfe6bd0b05d984db02/resolv.conf",
> "HostnamePath": "/var/lib/docker/containers/b256cce8eb8fb26f30270a837bb3e38cd382a20dc402b0dfe6bd0b05d984db02/hostname",
> "HostsPath": "/var/lib/docker/containers/b256cce8eb8fb26f30270a837bb3e38cd382a20dc402b0dfe6bd0b05d984db02/hosts",
> "LogPath": "/var/lib/docker/containers/b256cce8eb8fb26f30270a837bb3e38cd382a20dc402b0dfe6bd0b05d984db02/b256cce8eb8fb26f30270a837bb3e38cd382a20dc402b0dfe6bd0b05d984db02-json.log",
57,58c57,58
< "MountLabel": "system_u:object_r:svirt_sandbox_file_t:s0:c836,c866",
< "ProcessLabel": "system_u:system_r:svirt_lxc_net_t:s0:c836,c866",
---
> "MountLabel": "system_u:object_r:svirt_sandbox_file_t:s0:c307,c890",
> "ProcessLabel": "system_u:system_r:svirt_lxc_net_t:s0:c307,c890",
120,121c120,121
< "DeviceId": "106",
< "DeviceName": "docker-8:2-2124-7a9675ad0b9dd40106a954856be32b57c30081eea7f16c94e77bc402bdba02bf",
---
> "DeviceId": "110",
> "DeviceName": "docker-8:2-2124-b256cce8eb8fb26f30270a837bb3e38cd382a20dc402b0dfe6bd0b05d984db02",
127,134c127,128
< "Source": "/app/etc/tls",
< "Destination": "/certs",
< "Mode": "rw",
< "RW": true
< },
< {
< "Name": "19f37ceddc9f1957f5f3888cb45559ec78d35ce7a71a8ad5f9d9888f427ec96e",
< "Source": "/var/lib/docker/volumes/19f37ceddc9f1957f5f3888cb45559ec78d35ce7a71a8ad5f9d9888f427ec96e/_data",
---
> "Name": "c6c54293f7dd3f8345a4d316e3f6cf6441cda41231834688f8d2aa25c090a68a",
> "Source": "/var/lib/docker/volumes/c6c54293f7dd3f8345a4d316e3f6cf6441cda41231834688f8d2aa25c090a68a/_data",
137a132,137
> "RW": true
> },
> {
> "Source": "/app/etc/tls",
> "Destination": "/certs",
> "Mode": "rw",