Hi List,
I’m trying to run a command as a different user like so:
Hi List,
I’m trying to run a command as a different user like so:
I believe you want sudo_user. User is the one you login as.
Ah ok,
I used the example from here:
https://gist.github.com/2897937
##########
# Run things as other users!
#
# Each task has an optional 'user' and 'sudo' flag to indicate which
# user a task should run as and whether or not to use 'sudo' to switch
# to that user.
- name: dump all postgres databases
action: pg_dumpall -w -f /tmp/backup.psql
user: postgres
sudo: False
But now it does work, thanks!
Hmm, either docs are wrong or code is not working as expected, either
way looks like a patch (to docs or code) is needed.
IIRC, only sudo_user could be set on a task, and not user. The docs
shouldn't imply user can be set on anything but a play, and it should
yell at you if you try.
Though if it doesn't yell at you, I'm inclined to think it's just a
bug that it doesn't currently work like that
Michael DeHaan wrote:
IIRC, only sudo_user could be set on a task, and not user. The docs
shouldn't imply user can be set on anything but a play, and it should
yell at you if you try.Though if it doesn't yell at you, I'm inclined to think it's just a
bug that it doesn't currently work like that
Actually, user: is an invocation of the user module, which is why it's
yelling at you for having two actions, so it appears to be doing the right
thing here.
Daniel
remote_user, might be what you are looking for
Hi all,
Thanks for the feedback.
I have indeed found the sudo_user in the playbooks manual section. So it was definitely explained already, I just used the wrong documentation.
Brian, I’m also looking for that remote_user, to see what the difference between the two are, but I cannot seem to find any reference for it in the official documentation?
Is the remote_user variable not only used inside the various module’s code?
Thanks,
Mark
Last I looked (a few months back) remote_user (aka login user) gets
evaluated at connection level w/o looking at tasks. You should be able
to set it at host or playbook level but not at task.
Correct, plays are more or less defined as the set of the user and
hosts/groups you are talking to a set of tasks.