angstwad/docker.ubuntu

sudo apt-key add - fails if sudo is not installed

swifmaneum opened this issue · 1 comments

Hi there!

Running the role on a fresh Debian 9 installation fails at the Alternative | Add Docker repository key task for me, as there is no sudo installed.

Rerunning the command manually without sudo did the trick for me. Is there an easy way to prevent this error or to check whether sudo is installed and go ahead accordingly?

The exact error looks like this:

fatal: [192.168.99.197]: FAILED! => {"changed": true, "cmd": "curl -sSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -", "delta": "0:00:00.084067", "end": "2017-07-20 10:58:56.051981", "failed": true, "rc": 127, "start": "2017-07-20 10:58:55.967914", "stderr": "/bin/sh: 1: sudo: not found\n(23) Failed writing body", "stderr_lines": ["/bin/sh: 1: sudo: not found", "(23) Failed writing body"], "stdout": "", "stdout_lines": []}

Yeah, this is a legit bug. https://github.com/angstwad/docker.ubuntu/blob/master/tasks/main.yml#L79

It because when apt-key doesn't exist, it moves on to try it at the shell. We need to properly exec the command with the proper privilege escalation method.

PR's are welcome. Not sure when I'll get to this.