Can't understand output

Hello,

I’m trying Ansible without playbooks. Just oneliner from console. Want to do ‘apt-get update’ on remote server.

Here is ansible.cfg:

[defaults]
remote_port = 2224
remote_user = che
sudo_user = che

Here is command:

ansible my.domain.com -vvvv -S -m apt -a update_cache=yes

Che in sudo users on my.domain.com machine and can perform commands without password.

Here is command output:

<my.domain.com> ESTABLISH CONNECTION FOR USER: che
<my.domain.com> REMOTE_MODULE apt update_cache=yes
<my.domain.com> EXEC ssh -C -tt -vvv -o ControlMaster=auto -o ControlPersist=60s -o ControlPath=“/Users/che/.ansible/cp/ansible- ssh-%h-%p-%r” -o Port=2224 -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased ,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 my.domain.com /bin/sh -c ‘mkdir -p $HOME/.ansible/tmp/ansible-tmp-1 417710259.52-145934245462641 && chmod a+rx $HOME/.ansible/tmp/ansible-tmp-1417710259.52-145934245462641 && echo $HOME/.ansible/t mp/ansible-tmp-1417710259.52-145934245462641’
<my.domain.com> PUT /var/folders/5t/3h0pmhsj0m1_ry0kdwq9jg5h0000gn/T/tmpF2t29z TO /home/che/.ansible/tmp/ansible-tmp-1417710259. 52-145934245462641/apt
<my.domain.com> EXEC ssh -C -tt -vvv -o ControlMaster=auto -o ControlPersist=60s -o ControlPath=“/Users/che/.ansible/cp/ansible- ssh-%h-%p-%r” -o Port=2224 -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased ,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 my.domain.com /bin/sh -c ‘su root -c “/bin/sh -c '”’“‘echo SUDO-SUC CESS-mtfrixxottefdaxagqopjyeswrarmlxn; LANG=en_US.UTF-8 LC_CTYPE=en_US.UTF-8 /usr/bin/python /home/che/.ansible/tmp/ansible-tmp- 1417710259.52-145934245462641/apt; rm -rf /home/che/.ansible/tmp/ansible-tmp-1417710259.52-145934245462641/ >/dev/null 2>&1’”‘"’ "’

And just get stuck. Is it normal, or I must find where is a problem?

Hi Paul,

Looking at your options you’ve not specified any action for apt to take beyond updating the cache (the only -a option you show is “update_cache=yes”), which itself should be an error. I believe you want to add “upgrade=safe”, so please let us know if it still hangs after adding that.

Thank you for your answer!

Looks like sudo problems:

“msg”: “‘/usr/bin/aptitude safe-upgrade’ failed: E: Could not open lock file /var/lib/dpkg/lock - open (13: Permission denied)\nE: Unable to lock the administration directory (/var/lib/dpkg/), are you root?\n”,

But my user is sudo user with NOPASSWD. And I can do “apt-get update” or “apt-get safe-upgrade” on server without any problems.

I see you’re using “-S”, which is --su. You will want to use -s or --sudo instead.

Sorry, it’s old command. I’ve tried -s already. Same thing.

from your first email I see that you have:

sudo_user = che

in your defaults file. That’s likely the source of this portion of the issue. sudo_user means “the user that you want to sudo to”. So you want it to be root (which is the default so you should be fine if you just get rid of that line).

You were probably thinking that you needed to specify the user to sudo from. In ansible the user that you sudo from is the user that ansible is ssh’ing into the box as. In your defaults you’re setting remote_user=che so that’s the user that will be sudo’d from.

-Toshio

I just found it too :))
Thank you, Toshio, anyway!