With a personal user account (userx) I run the ansible playbook on all my specified hosts. In ansible.cfg the remote user (which can become root) to be used is:
remote_user = ansible
For the remote hosts this all works fine. It connects as the user Ansible, and executes all tasks as wished for, also changing information (like /etc/ssh/sshd_config
) which requires root rights.
But now I also want to execute the playbook on the Ansible host itself. I put the following in my inventory file:
localhost ansible_connection=local
which now indeed executes on localhost. But as userx, and this results in "Access denied" for some task it needs to do.
This is of course somewhat expected, since remote_user tells something about remote, not the local user. But still, I expected that the playbook would --become
locally too, to execute the tasks as root (e.g. sudo su -
). It seems no to do that.
Running the playbook with --become -vvv
tells me
<localhost> ESTABLISH LOCAL CONNECTION FOR USER: userx
and it seems not to try to execute the tasks with sudo. And without using sudo, the task fails.
How can I tell ansible to to use sudo / become on the local connection too?
ansible
user, which had the correct rights. Locally, the specific task neededbecome
. I tried to specify this at the inventory-file level, but misusedansible_become
by setting it to=ansible
(evaluates to false). And then the inventory file has precedence over the command-line--become
, which finally led to a failing task. – Financial