I am trying to run a specific Ansible task as a different user than the one who is running the playbook. My
.yml file looks like this:
--- - hosts: staging_servers tasks: - name: check user remote_user: someusername shell: whoami
Running this task shows me that
whoami command returns a different user than I defined in the task (precisely, returns the user which is defined in
hosts file called
I also tried to define the task like this:
--- - hosts: staging_servers tasks: - name: check user sudo: yes sudo_user: someusername shell: whoami
but then I get '
Missing sudo password' error, although there is a line in
sudoers file which says
someusername ALL=(ALL) NOPASSWD:ALL and issuing commands with
sudo on remote machine as
someusername doesn't ask me for a password.
So, how can I run the specific task as a different user which is not the user defined in
hosts file or