# docker module how to get  --cap-add=NET\_ADMIN

**URL:** <https://forum.ansible.com/t/docker-module-how-to-get-cap-add-net-admin/18000>\
**Category:** Ansible Project\
**Tags:** ubuntu\
**Created:** [April 17, 2015, 1:32am UTC](https://forum.ansible.com/t/docker-module-how-to-get-cap-add-net-admin/18000 "2015-04-17T01:32:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Steve\_Kieu](https://avatars.discourse-cdn.com/v4/letter/s/41988e/32.png) [@Steve\_Kieu](https://forum.ansible.com/u/Steve_Kieu)\
**Post date:** [April 17, 2015, 1:32am UTC](https://forum.ansible.com/t/docker-module-how-to-get-cap-add-net-admin/18000/1 "2015-04-17T01:32:37Z")

</div>

Hi team,

I am sorry if it has been answered somewhere but my google search does not show yet. How can I get something like --cap-add=NET\_ADMIN when using docker module to start a docker container

my exmaple like below (not run and tested yet)

- name: jenkins master - ubuntu  
docker:  
name: test-jenkinsmaster-ubuntu  
command: ‘/scripts/run.sh “192.168.2.41/24”’  
image: 10.10.4.229:5000/jumbo:base\_ubuntu14  
state: present  
dns: 192.168.2.1  
insecure\_registry: yes  
env: SHELL=“/usr/sbin/sshd -D” GATEWAY=“192.168.2.1” DNS\_SERVER=“192.168.2.1”

as inside the docker image the start command /scripts/run.sh will take first arg and set IP (that is a simple way I get static IP) for now. However it needs --cap-add=NET\_ADMIN and I do not want to give it all right using privileged: yes.

Also the --add-host options as well.

Thanks a lot in advance.

---

<div class="post-metadata">

**Author:** ![Steve\_Kieu](https://avatars.discourse-cdn.com/v4/letter/s/41988e/32.png) [@Steve\_Kieu](https://forum.ansible.com/u/Steve_Kieu)\
**Post date:** [April 17, 2015, 2:46am UTC](https://forum.ansible.com/t/docker-module-how-to-get-cap-add-net-admin/18000/2 "2015-04-17T02:46:09Z")

</div>

Having a look at the source code and looks like it is not supported yet. However docker-py support it so it is trivial to add it in - I guess in

def create\_containers(self, count=1):  
params = {‘image’: self.module.params.get(‘image’),  
‘command’: self.module.params.get(‘command’),  
‘ports’: self.exposed\_ports,  
‘volumes’: self.volumes,  
‘mem\_limit’: \_human\_to\_bytes(self.module.params.get(‘memory\_limit’)),  
‘environment’: self.env,  
‘hostname’: self.module.params.get(‘hostname’),  
‘detach’: self.module.params.get(‘detach’),  
‘name’: self.module.params.get(‘name’),  
‘stdin\_open’: self.module.params.get(‘stdin\_open’),  
‘tty’: self.module.params.get(‘tty’),  
}

add it in the params and it would be good.

Is the any demand for that feature?

Thanks

---

<div class="post-metadata">

**Author:** ![Steve\_Kieu](https://avatars.discourse-cdn.com/v4/letter/s/41988e/32.png) [@Steve\_Kieu](https://forum.ansible.com/u/Steve_Kieu)\
**Post date:** [April 17, 2015, 3:11am UTC](https://forum.ansible.com/t/docker-module-how-to-get-cap-add-net-admin/18000/3 "2015-04-17T03:11:14Z")

</div>

> Here is the patch and I tested it - patch against docker.py - ansible version 1.8.4

— docker.py 2015-02-20 04:02:51.000000000 +1000  
+++ docker1.py 2015-04-17 13:05:00.000000000 +1000  
@@ -204,7 +204,12 @@  
default: ‘’  
aliases:   
version\_added: “1.8”
