Repository: ansible/ansible

Issue:
Feature idea: docker_container support for --userns 
_From @ko-christ on September 27, 2016 13:46_

##### ISSUE TYPE
- Feature Idea
##### COMPONENT NAME

docker_container
##### ANSIBLE VERSION

```
ansible 2.1.1.0
  config file = 
  configured module search path = Default w/o overrides
```
##### CONFIGURATION
##### OS / ENVIRONMENT
##### SUMMARY

Docker allows setting the `userns` mapping, but docker_container currently does not support this functionality. It would be great to add support for this in `docker_container` module as well.

`userns_mode` also seems to be available with `docker-py` version `1.10.0`.
https://github.com/docker/docker-py/pull/1113


_Copied from original issue: ansible/ansible-modules-core#5054_


Discussion:
_From @ansibot on September 27, 2016 14:6_

<!-- @ko-christ: Thanks for filing this feature idea! -->

@ansible ping, this issue is waiting for your response.
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)

<!--- boilerplate: issue_bug_new --->

_From @markusthoemmes on October 11, 2016 13:13_

This is definitely needed. User namespaces were one of the killer features of docker 1.12

_From @domdom82 on October 11, 2016 13:16_

Yep, this is super-important to have.

_From @jeremiaswerner on October 11, 2016 13:37_

👍 

_From @ansibot on November 28, 2016 9:34_

@ansible, ping. This issue is still waiting on your response.
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: issue_renotify_maintainer --->
_From @ansibot on December 7, 2016 19:10_

This repository has been locked. All new issues and pull requests should be filed in https://github.com/ansible/ansible

Please read through the <a href="http://docs.ansible.com/ansible/dev_guide/repomerge.html#move-issues-and-prs-to-new-repo">repomerge</a> page in the dev guide. The guide contains links to tools which automatically move your issue or pull request to the ansible/ansible repo.

<!-- boilerplate: repomerge -->

Resolving patch:
diff --git a/lib/ansible/modules/cloud/docker/docker_container.py b/lib/ansible/modules/cloud/docker/docker_container.py
--- a/lib/ansible/modules/cloud/docker/docker_container.py
+++ b/lib/ansible/modules/cloud/docker/docker_container.py
@@ -266,6 +266,12 @@
       - none
     default: null
     required: false
+  userns_mode:
+     description:
+       - User namespace to use
+     default: null
+     required: false
+     version_added: "2.5"
   networks:
      description:
        - List of networks the container belongs to.
@@ -727,6 +733,7 @@ def __init__(self, client):
         self.memory_swappiness = None
         self.name = None
         self.network_mode = None
+        self.userns_mode = None
         self.networks = None
         self.oom_killer = None
         self.oom_score_adj = None
@@ -916,6 +923,7 @@ def _host_config(self):
             binds='volume_binds',
             volumes_from='volumes_from',
             network_mode='network_mode',
+            userns_mode='userns_mode',
             cap_add='capabilities',
             extra_hosts='etc_hosts',
             read_only='read_only',
@@ -1242,6 +1250,7 @@ def has_different_configuration(self, image):
             mac_address=network.get('MacAddress'),
             memory_swappiness=host_config.get('MemorySwappiness'),
             network_mode=host_config.get('NetworkMode'),
+            userns_mode=host_config.get('UsernsMode'),
             oom_killer=host_config.get('OomKillDisable'),
             oom_score_adj=host_config.get('OomScoreAdj'),
             pid_mode=host_config.get('PidMode'),
@@ -1975,6 +1984,7 @@ def main():
         memory_swappiness=dict(type='int'),
         name=dict(type='str', required=True),
         network_mode=dict(type='str'),
+        userns_mode=dict(type='str'),
         networks=dict(type='list'),
         oom_killer=dict(type='bool'),
         oom_score_adj=dict(type='int'),


Test patch: