User permissions issue.

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.
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

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.

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) 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).
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). 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

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

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

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

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