I give up, just can't understand how to use Ansible with "connection: local" + "sudo: yes". I have something like:
ansible-playbook ansible/desktop.yml
- hosts: localhost
connection: local
...
tasks:
- apt_repository: repo='ppa:alexey-smirnov/deadbeef'
sudo: yes
I've also tried sudo_user: ...
param, sudo
before the command, ansible-playbook --sudo
and --ask-sudo-pass
Currently:
failed: [localhost] => {"failed": true}
msg: [Errno 13] Permission denied
How should it be executed?
ansible --version
ansible 1.7.2
Ansible Sudo or become is a method to run a particular task in a playbook with Special Privileges like root user or some other user. become and become_user both have to be used in a playbook in certain cases where you want your remote user to be non-root.it is more like doing sudo -u someuser before running a task.
Using localhost in ansible playbook hosts argumentIn the hosts argument mention localhost so this entire playbook will run on locally or ansible control machine. This playbook will run on your local machine. Note: you can also mention 127.0. 0.1 in the place of localhost the playbook, Both localhost and 127.0.
It is to execute the tasks locally on the same host (i.e., the controller) where the playbook is run. From the documentation, It may be useful to use a playbook locally, rather than by connecting over SSH. Follow this answer to receive notifications. answered Mar 18, 2020 at 19:30.
Try
ansible-playbook -i <inventory> ansible/desktop.yml -u <local user who can sudo with password> --ask-sudo-pass
This will make ansible use the remote user you mentioned in -u
. And when it uses that user to sudo, it will ask you for sudo password.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With