Reputation: 20182
I am running the following task to run a debian package on an ubuntu 14 OS using Ansible 2.1 but getting the exception copied below. The remote user does have sudo privileges on the remote machine.
- name: run dpkg
shell: dpkg -i {{ debian_build.stdout }}
become: true
become_user: ubuntu
become_method: sudo
error
fatal: [testserver]: FAILED! => {"changed": true, "cmd": "dpkg -i /home/ubuntu/test-server_0.1.0-7c47d103f8da21045e3ee817529eb84a0aa79723_all.deb", "delta": "0:00:00.002444", "end": "2016-10-10 14:33:32.014887", "failed": true, "rc": 2, "start": "2016-10-10 14:33:32.012443", "stderr": "dpkg: error: requested operation requires superuser privilege", "stdout": "", "stdout_lines": [], "warnings": []}
Upvotes: 2
Views: 1409
Reputation: 1070
Because this;
become: true
become_user: ubuntu
become_method: sudo
Is the equivelant of doing this on shell:
myuser$ sudo su ubuntu
ubuntu$
You are using sudo to switch to a non-privileged user account. "Ubuntu" does not have access to run dpkg without invoking sudo, which is why your playbook works if you put sudo in your shell command.
You also shouldn't be using become to switch to a unprivileged user per Ansible best practices: http://docs.ansible.com/ansible/become.html#becoming-an-unprivileged-user
You should run this playbook as the correct user to begin with by using remote_user for example.
Upvotes: 3