Sergey
Sergey

Reputation: 21171

Can I use sudo in Ansible with connection "local"?

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

Upvotes: 6

Views: 5462

Answers (2)

Jordan
Jordan

Reputation: 261

Here's another method (also works with ansible become: syntax):

sudo su -c "ansible-playbook <your playbook name and options>"

Upvotes: 0

Zasz
Zasz

Reputation: 12538

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.

Upvotes: 3

Related Questions