# User permissions issue.

**URL:** <https://forum.ansible.com/t/user-permissions-issue/13013>\
**Category:** Ansible Project\
**Created:** [June 23, 2013, 5:13pm UTC](https://forum.ansible.com/t/user-permissions-issue/13013 "2013-06-23T17:13:41Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jonathan\_Barronvill1](https://avatars.discourse-cdn.com/v4/letter/j/49beb7/32.png) [@Jonathan\_Barronvill1](https://forum.ansible.com/u/Jonathan_Barronvill1)\
**Post date:** [June 23, 2013, 5:13pm UTC](https://forum.ansible.com/t/user-permissions-issue/13013/1 "2013-06-23T17:13:41Z")

</div>

Hey all.

I have a very simple VM that I’m attempting to do some basic provisioning on with Ansible through Vagrant: [http://github.com/jonathanmarvens/working-vm](http://github.com/jonathanmarvens/working-vm).  
I’ve been having issues getting it to work. I know that my problem has something to do with user permissions, but I can’t seem to find the exact problem.  
I’m wondering if anyone here would be willing to take a look at the source and tell me where I’m being idiot?

Thanks.

- Jonathan

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [June 23, 2013, 5:31pm UTC](https://forum.ansible.com/t/user-permissions-issue/13013/2 "2013-06-23T17:31:00Z")

</div>

When you say “an issue getting it to work”, can you describe symptoms?

Much better if you can err on the side of more data.

---

<div class="post-metadata">

**Author:** ![Jonathan\_Barronvill1](https://avatars.discourse-cdn.com/v4/letter/j/49beb7/32.png) [@Jonathan\_Barronvill1](https://forum.ansible.com/u/Jonathan_Barronvill1)\
**Post date:** [June 23, 2013, 5:54pm UTC](https://forum.ansible.com/t/user-permissions-issue/13013/3 "2013-06-23T17:54:05Z")

</div>

I apologize for being so vague.

Here’s the problem.  
I’m using Vagrant (with the official Ansible provisioner: [http://docs.vagrantup.com/v2/provisioning/ansible.html](http://docs.vagrantup.com/v2/provisioning/ansible.html)) with an Ubuntu Server 12.04 cloud image box. The box is set up as it should be ([http://docs-v1.vagrantup.com/v1/docs/base\_boxes.html](http://docs-v1.vagrantup.com/v1/docs/base_boxes.html)).  
At the moment, I’m using Ansible v1.1.  
I have a main play “main.yml” ([http://github.com/jonathanmarvens/working-vm/blob/develop/ansible/main.yml](http://github.com/jonathanmarvens/working-vm/blob/develop/ansible/main.yml)). What I want is for certain tasks of the main play to run with root permissions, but not the entire play. And since this VM has password-less sudo set up as it should, I don’t expect a password to be requested of me.  
I’ve tried many different things, including setting **“root”** as the value for the **user** section in the task that requires root permissions, but it turns out that, due to the “action shorthands”, the **user** module takes over instead.

I hope that I’m a bit clearer now.

Thanks.

- Jonathan

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [June 23, 2013, 5:57pm UTC](https://forum.ansible.com/t/user-permissions-issue/13013/4 "2013-06-23T17:57:49Z")

</div>

Ok, so I think what you want here is something like this:

tasks:

- name: this runs without sudo  
shell: echo hi

- name: this runs WITH sudo  
shell: echo hi SUDO!  
sudo: True

I believe (but I’m fighting a decent headache and haven’t checked), you can also set sudo\_user: at the task level if you need to use multiple other user accounts.

The other thing you can of course do is start a new play, if you find yourself repeating the sudo line too much.

At play level, to engage sudo, it’s just like:

- hosts: foo  
sudo: True  
sudo\_user: root # this is actually the default  
tasks: …

And of course you can have multiple plays in the same file if you want.

Hope this helps!

–Michael

---

<div class="post-metadata">

**Author:** ![Jonathan\_Barronvill1](https://avatars.discourse-cdn.com/v4/letter/j/49beb7/32.png) [@Jonathan\_Barronvill1](https://forum.ansible.com/u/Jonathan_Barronvill1)\
**Post date:** [June 23, 2013, 6:48pm UTC](https://forum.ansible.com/t/user-permissions-issue/13013/5 "2013-06-23T18:48:28Z")

</div>

Hey Michael.

Your suggestion isn’t working for me, but I thinking now that this _may_ be an issue with Vagrant. I’ll figure it out anyway.

Much thanks for your help! [:)].  
You guys (AnsibleWorks) are awesome.

- Jonathan

---

<div class="post-metadata">

**Author:** ![Jonathan\_Barronvill1](https://avatars.discourse-cdn.com/v4/letter/j/49beb7/32.png) [@Jonathan\_Barronvill1](https://forum.ansible.com/u/Jonathan_Barronvill1)\
**Post date:** [June 23, 2013, 6:49pm UTC](https://forum.ansible.com/t/user-permissions-issue/13013/6 "2013-06-23T18:49:56Z")

</div>

P.S. You may want to get yourself some rest for that decent headache of yours.

---

<div class="post-metadata">

**Author:** ![Mark\_Mandel](https://avatars.discourse-cdn.com/v4/letter/m/bc79bd/32.png) [@Mark\_Mandel](https://forum.ansible.com/u/Mark_Mandel)\
**Post date:** [June 23, 2013, 8:59pm UTC](https://forum.ansible.com/t/user-permissions-issue/13013/7 "2013-06-23T20:59:02Z")

</div>

Just having a quick look, ansible won’t know the port to connect to on localhost.

From the vagrant docs, it recommends that you hard code the vm’s ip in the Vagrantfile and ansible host file.

Failing that, you can use the vagrant external inventory plugin that ships with ansible 1.2 to do the lookup for you.

Hth

Mark
