unable to run plays with sudo rights

508 views
Skip to first unread message

Steve Smith

unread,
Feb 21, 2014, 2:32:11 PM2/21/14
to ansible...@googlegroups.com
I'm having trouble running ansible plays as root. I have a user (user_x) on an Ubuntu server (12.04) who has sudo rights and I can run sudo commands on the server. I am able to ping the server and gather facts as user_x. However, when I run a play that requires sudo, in this case 

  -name: ensure apache & php are installed
     apt: pkg={{ item }} state=present update_cache=yes cache_valid_time=86400
     with_items:
       - apache2
       - php5

The play fails with the error 
msg: 'apt-get install 'apache2' 'php5' ' failed: E: Could not open lock file /var/lib/dpkg/lock - open (13: Permission denied) 
E: Unable to lock the administration directory (/var/lib/dpkg/), are you root? 

The variables are the defaults and I'm calling the playbook like so

ansible-playbook site.yml --limit staging


Any help would be appreciated.
 
 
 

Timothy Gerla

unread,
Feb 21, 2014, 3:25:48 PM2/21/14
to ansible-project
Hi Steve,

Are you specifying "sudo: true" in the task or in the play? You can do that, or you can pass "--sudo" to the command line for a one-off setting for the entire playbook. But you do have to tell Ansible when/where to sudo.

Hope this helps!

-Tim


--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



--

Steve Smith

unread,
Feb 21, 2014, 5:45:33 PM2/21/14
to ansible...@googlegroups.com
Thanks, Tim.

I misunderstood and was trying to set sudo as a variable rather than a task/handler parameter. 

Having watched your great Quick Start Video, I didn't realize I'd have to use the -K option when calling the playbook, since Ubuntu's default is to not enable a root user. In order to have the kind of effortless automation you demonstrate in the video I'd have to: a) run as root, b) use NOPASSWD in the sudoers file, or c) install the user_x's ssh key in the root known_hosts file. Am I understanding this correctly?

Thanks much!
Steve
Reply all
Reply to author
Forward
0 new messages