1

I am trying to use ansible, but I seem to not be able to get it to work with sudo. I have minimised the problem to this:

This does not work:

ansible localhost --ask-become-pass -m shell  -a "cat  /var/log/syslog"

Gives this output: I type password, then it errors.

SUDO password:
localhost | FAILED | rc=1 >>
cat: /var/log/syslog: Permission denied

These work fine:

ssh -t localhost sudo cat /var/log/syslog #without ansible
ansible localhost -m shell -a "ls" #without sudo

Other diagnostics:

#expecting last line to be `root`
ansible localhost  --become-user=root --ask-become-pass -m shell  -a "whoami"

gives this output, when correct password entered.

SUDO password:
localhost | SUCCESS | rc=0 >>
richard
0

You could try to add this to the command when you run --ask-become-pass

So, ansible yoga --become-user=root --ask-become-pass -m shell -a "cat /var/log/syslog"

  • --become-user=root, did not help (no change). And the manual says it defaults to root. – ctrl-alt-delor Aug 28 '17 at 18:30
0

It seems that --ask-become-pass is not enough, you also need the --become param. Therefore the command is: ansible localhost --become --ask-become-pass -m shell -a "cat /var/log/syslog".

I have also noticed that I do not need --ask-become-pass, I think the password is being cached, like sudo does.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.