# \[DOCKER\] Explicited sudo command permissions. NO ALL

**URL:** <https://forum.ansible.com/t/docker-explicited-sudo-command-permissions-no-all/28196>\
**Category:** Ansible Project\
**Created:** [July 30, 2018, 2:27pm UTC](https://forum.ansible.com/t/docker-explicited-sudo-command-permissions-no-all/28196 "2018-07-30T14:27:53Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Guilherme\_Xavier](https://avatars.discourse-cdn.com/v4/letter/g/5fc32e/32.png) [@Guilherme\_Xavier](https://forum.ansible.com/u/Guilherme_Xavier)\
**Post date:** [July 30, 2018, 2:27pm UTC](https://forum.ansible.com/t/docker-explicited-sudo-command-permissions-no-all/28196/1 "2018-07-30T14:27:53Z")

</div>

SUMMARY

My company work with sudo for docker operations, but my user can't become  
root. I just can use commands as root in form "sudo docker ps", "sudo  
docker run ...", "sudo docker images" etc. I can't use "sudo su - " or  
"sudo echo test" per example. The commands are explicity declarated.

My stdout of "sudo -l" command execution:

User MYUSER may run the following commands on THISSERVER:  
(root) NOPASSWD: /usr/bin/docker

Isn't an option, to change "/usr/bin/docker" to "ALL" because these setting  
aren't my scope.

COMPONENT NAME

docker\_images

ANSIBLE VERSION

ansible 2.6.1  
&nbsp;&nbsp;config file = /etc/ansible/ansible.cfg  
&nbsp;&nbsp;configured module search path = [u'/home/oi367730/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']  
&nbsp;&nbsp;ansible python module location = /usr/lib/python2.7/site-packages/ansible  
&nbsp;&nbsp;executable location = /usr/bin/ansible  
&nbsp;&nbsp;python version = 2.7.5 (default, Jul 13 2018, 13:06:57) [GCC 4.8.5 20150623 (Red Hat 4.8.5-28)]

CONFIGURATION  
OS / ENVIRONMENT

CentOS 7.5.1804

STEPS TO REPRODUCE

I wanna download a any image, soo i can use shell module, like:

- name: "Root Tasks"  
&nbsp;&nbsp;hosts: all  
&nbsp;&nbsp;remote\_user: MYUSER  
&nbsp;&nbsp;tasks:  
&nbsp;&nbsp;&nbsp;&nbsp;- name: Task Name  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;shell: sudo docker pull $IMAGENAME

BUT I wanna use the docker\_image module, like:

- name: Testing Docker  
&nbsp;&nbsp;hosts: all  
&nbsp;&nbsp;remote\_user: MYUSER  
&nbsp;&nbsp;tasks:  
&nbsp;&nbsp;- name: Test  
&nbsp;&nbsp;&nbsp;&nbsp;become: yes  
&nbsp;&nbsp;&nbsp;&nbsp;docker\_image:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;name: $IMAGENAME

EXPECTED RESULTS

I expect these two executions work.

ACTUAL RESULTS

fatal: [SERVER]: FAILED! =\> {  
&nbsp;&nbsp;&nbsp;&nbsp;"changed": false,  
&nbsp;&nbsp;&nbsp;&nbsp;"module\_stderr": "OpenSSH\_7.4p1, OpenSSL 1.0.2k-fips 26 Jan 2017\r\ndebug1: Reading configuration data /etc/ssh/ssh\_config\r\ndebug1: /etc/ssh/ssh\_config line 58: Applying options for \*\r\ndebug1: auto-mux: Trying existing master\r\ndebug2: fd 3 setting O\_NONBLOCK\r\ndebug2: mux\_client\_hello\_exchange: master version 4\r\ndebug3: mux\_client\_forwards: request forwardings: 0 local, 0 remote\r\ndebug3: mux\_client\_request\_session: entering\r\ndebug3: mux\_client\_request\_alive: entering\r\ndebug3: mux\_client\_request\_alive: done pid = 6691\r\ndebug3: mux\_client\_request\_session: session request sent\r\ndebug1: mux\_client\_request\_session: master session id: 2\r\ndebug3: mux\_client\_read\_packet: read header failed: Broken pipe\r\ndebug2: Received exit status from master 1\r\nShared connection to SERVER closed.\r\n",  
&nbsp;&nbsp;&nbsp;&nbsp;"module\_stdout": "sudo: a password is required\r\n",  
&nbsp;&nbsp;&nbsp;&nbsp;"msg": "MODULE FAILURE",  
&nbsp;&nbsp;&nbsp;&nbsp;"rc": 1  
}

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [July 30, 2018, 2:34pm UTC](https://forum.ansible.com/t/docker-explicited-sudo-command-permissions-no-all/28196/2 "2018-07-30T14:34:48Z")

</div>

The Ansible docker modules do not execute the docker CLI commands. They instead use the docker python module, which would require you to be allowed to run python via sudo.

If you are constrained to this path, you will have to use the `shell` or `command` modules to execute the docker CLI.

Otherwise, you could ask whoever runs your servers to add your user to the `docker` group, which would prevent needing to use sudo.

---

<div class="post-metadata">

**Author:** ![Guilherme\_Xavier](https://avatars.discourse-cdn.com/v4/letter/g/5fc32e/32.png) [@Guilherme\_Xavier](https://forum.ansible.com/u/Guilherme_Xavier)\
**Post date:** [July 30, 2018, 2:50pm UTC](https://forum.ansible.com/t/docker-explicited-sudo-command-permissions-no-all/28196/3 "2018-07-30T14:50:38Z")

</div>

Thanks for reply, Matt! This is exactly what I need to know. I will test some approaches and try to solve my problem. Thanks again!

---

<div class="post-metadata">

**Author:** ![bala](https://avatars.discourse-cdn.com/v4/letter/b/94ad74/32.png) [@bala](https://forum.ansible.com/u/bala)\
**Post date:** [July 30, 2018, 2:55pm UTC](https://forum.ansible.com/t/docker-explicited-sudo-command-permissions-no-all/28196/4 "2018-07-30T14:55:02Z")

</div>

pl try adding user to sudoer

```auto
grep dwalsh /etc/sudoers
dwalsh ALL=(ALL) NOPASSWD: /usr/bin/docker

```
