-K option sets user to root

With this playbook (bug.yml):


  • hosts: dev
    user: soa
    tasks:
  • name: create a file
    command: /bin/touch /tmp/file

If I run:

ansible-playbook bug.yml

The resulting file looks like this:

ls -l /tmp/file
-rw-r–r–. 1 soa soa 0 Jul 25 09:21 /tmp/file

But if I run it with -K:

ansible-playbook -K bug.yml

I get:

ls -l /tmp/file
-rw-r–r–. 1 root root 0 Jul 25 09:23 /tmp/file

You can see that this command was really run as root.

This is a big problem that I originally discovered while trying to use the git command.

When ansible forces git to run as root, github does not know who the user is and ansible hangs.

Is this a bug?

-K is “–ask-sudo-pass”.

Can you clarify what version of ansible you are using?

Newer versions (1.3 devel) should not do this so some plays can be sudo and others not.

However, previously it did assume that if you requested a sudo password it implied you wanted to sudo, and the default sudo user
if unspecified is root.