# docker\_container module always falsely report 'changed' and 'kernel\_memory' attribute seems to be the culprit

**URL:** <https://forum.ansible.com/t/docker-container-module-always-falsely-report-changed-and-kernel-memory-attribute-seems-to-be-the-culprit/28026>\
**Category:** Ansible Project\
**Created:** [July 11, 2018, 12:41pm UTC](https://forum.ansible.com/t/docker-container-module-always-falsely-report-changed-and-kernel-memory-attribute-seems-to-be-the-culprit/28026 "2018-07-11T12:41:55Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![ishan\_jain](https://avatars.discourse-cdn.com/v4/letter/i/dc4da7/32.png) [@ishan\_jain](https://forum.ansible.com/u/ishan_jain)\
**Post date:** [July 11, 2018, 12:41pm UTC](https://forum.ansible.com/t/docker-container-module-always-falsely-report-changed-and-kernel-memory-attribute-seems-to-be-the-culprit/28026/1 "2018-07-11T12:41:55Z")

</div>

I have a playbook which in the end ensure that a docker container with provided attributes is started. So consider this task below (stripped off some of the stuff)

`

- name: Start container  
docker\_container:  
name: “{{cname}}”  
image: “{{ image }}”  
state: started  
memory: “{{ mem }}”  
memory\_reservation: “{{ memr }}”  
memory\_swap: “{{ mems }}”  
kernel\_memory: 0

`

This setup was working fine earlier but when i updated to Ansible 2.4.3, this container task would **always report changed** , while nothing at all is changed for the container on docker host. The container is not even being restarted and yet this task would show ‘changed’. I tried to compare the json returned by the above task with the json of docker inspect on my container, and they were exactly the same.

During debugging, i started commenting out some attributes and when i commented out ‘kernel\_memory’, it stopped reporting ‘changed’ and now it is back to the intended behavior of ‘OK’. So i know this attribute is the culprit, i just don’t know what is wrong. I check Ansible 2.6 as well and it has the same problem.

Can anyone please explain what am i doing wrong here or is it some problem in the docker\_container module ?

---

<div class="post-metadata">

**Author:** ![felixfontein](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/felixfontein/32/7530_2.png) [@felixfontein](https://forum.ansible.com/u/felixfontein)\
**Post date:** [July 11, 2018, 8:39pm UTC](https://forum.ansible.com/t/docker-container-module-always-falsely-report-changed-and-kernel-memory-attribute-seems-to-be-the-culprit/28026/2 "2018-07-11T20:39:07Z")

</div>

Hi,

> I have a playbook which in the end ensure that a docker container  
> with provided attributes is started. So consider this task below  
> (stripped off some of the stuff)
> 
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- name: Start container  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;docker\_container:  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;name: "{{cname}}"  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;image: "{{ image }}"  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;state: started  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;memory: "{{ mem }}"  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;memory\_reservation: "{{ memr }}"  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;memory\_swap: "{{ mems }}"  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;kernel\_memory: 0
> 
> This setup was working fine earlier but when i updated to Ansible  
> 2.4.3, this container task would \*always report changed\*, while

which version of Ansible did you use before? And did you also upgrade  
the docker-py / docker Python package (on the nodes)?

> During debugging, i started commenting out some attributes and when i  
> commented out 'kernel\_memory', it stopped reporting 'changed' and now  
> it is back to the intended behavior of 'OK'. So i know this attribute  
> is the culprit, i just don't know what is wrong. I check Ansible 2.6  
> as well and it has the same problem.
> 
> Can anyone please explain what am i doing wrong here or is it some  
> problem in the docker\_container module ?

I debugged this a bit; the problem is that the argument kernel\_memory  
("0", i.e. as a string) is compared to a number (0); the comparison  
fails and docker\_container things there is some work to do. I've looked  
at various versions of the docker\_container module, the code always  
looked very similar, so I doubt this ever worked differently.

(Actually, it could be that older versions did not set changed=True when  
updating the limits, so this wasn't visible with older versions of  
Ansible.)

Anyway, this is a bug in the docker\_container module IMO. You should  
create a ticket for it:  
[https://github.com/ansible/ansible/issues/new?template=bug\_report.md](https://github.com/ansible/ansible/issues/new?template=bug_report.md)

Cheers,  
Felix

---

<div class="post-metadata">

**Author:** ![ishan\_jain](https://avatars.discourse-cdn.com/v4/letter/i/dc4da7/32.png) [@ishan\_jain](https://forum.ansible.com/u/ishan_jain)\
**Post date:** [July 12, 2018, 2:36pm UTC](https://forum.ansible.com/t/docker-container-module-always-falsely-report-changed-and-kernel-memory-attribute-seems-to-be-the-culprit/28026/3 "2018-07-12T14:36:14Z")

</div>

Hi Felix,

Providing 0 or “0” values has the same undesired result. Although, if i provide empty value (‘’), then it runs just fine.

I have raised a bug here - [https://github.com/ansible/ansible/issues/42692](https://github.com/ansible/ansible/issues/42692)

BR,  
Ishan

---

<div class="post-metadata">

**Author:** ![Syed\_Jafar](https://avatars.discourse-cdn.com/v4/letter/s/a698b9/32.png) [@Syed\_Jafar](https://forum.ansible.com/u/Syed_Jafar)\
**Post date:** [July 12, 2018, 4:23pm UTC](https://forum.ansible.com/t/docker-container-module-always-falsely-report-changed-and-kernel-memory-attribute-seems-to-be-the-culprit/28026/4 "2018-07-12T16:23:00Z")

</div>

Could someone please let me know how to go about updating/patching Ubuntu systems via Ansible playbook.

---

<div class="post-metadata">

**Author:** ![Syed\_Jafar](https://avatars.discourse-cdn.com/v4/letter/s/a698b9/32.png) [@Syed\_Jafar](https://forum.ansible.com/u/Syed_Jafar)\
**Post date:** [July 13, 2018, 5:26pm UTC](https://forum.ansible.com/t/docker-container-module-always-falsely-report-changed-and-kernel-memory-attribute-seems-to-be-the-culprit/28026/5 "2018-07-13T17:26:32Z")

</div>

Can someone please tell me what I am doing wrong with the Ansible Playbook syntax. Listed below is the Playbook and the error I am getting.

# Basic provisioning example

- ec2:

key\_name: Ansible

instance\_type: t2.micro

image: ami-db710fa3

group\_id: sg-d271b9a2

wait: yes

volumes:

- device\_name: /dev/xvda

volume\_type: gp2

volume\_size: 8

delete\_on\_termination: true

count: 3

vpc\_subnet\_id: subnet-a29fdcf8

assign\_public\_ip: yes

ERROR! ‘ec2’ is not a valid attribute for a Play

The error appears to have been in ‘/private/etc/ansible/playbooks/ec2.yml’: line 2, column 3, but may

be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

# Basic provisioning example

- ec2:

^ here

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [July 13, 2018, 6:11pm UTC](https://forum.ansible.com/t/docker-container-module-always-falsely-report-changed-and-kernel-memory-attribute-seems-to-be-the-culprit/28026/6 "2018-07-13T18:11:59Z")

</div>

This is not a playbook but a task, recommend you read this  
[https://docs.ansible.com/ansible/latest/user\_guide/playbooks\_intro.html](https://docs.ansible.com/ansible/latest/user_guide/playbooks_intro.html)

---

<div class="post-metadata">

**Author:** ![Syed\_Jafar](https://avatars.discourse-cdn.com/v4/letter/s/a698b9/32.png) [@Syed\_Jafar](https://forum.ansible.com/u/Syed_Jafar)\
**Post date:** [July 18, 2018, 8:21pm UTC](https://forum.ansible.com/t/docker-container-module-always-falsely-report-changed-and-kernel-memory-attribute-seems-to-be-the-culprit/28026/7 "2018-07-18T20:21:08Z")

</div>

I live in Mountain View, CA and am looking for someone with Ansible expertise who I can spend 2-3 hours with in order to get up to speed with Ansible. I am willing to pay $100/hr or whatever it takes.

Thanks,  
Syed Jafar
