# Ansible vagrant - refuses to use vagrant user

**URL:** <https://forum.ansible.com/t/ansible-vagrant-refuses-to-use-vagrant-user/14207>\
**Category:** Ansible Project\
**Created:** [December 23, 2013, 2:24pm UTC](https://forum.ansible.com/t/ansible-vagrant-refuses-to-use-vagrant-user/14207 "2013-12-23T14:24:04Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![bryan\_hunt1](https://avatars.discourse-cdn.com/v4/letter/b/ed8c4c/32.png) [@bryan\_hunt1](https://forum.ansible.com/u/bryan_hunt1)\
**Post date:** [December 23, 2013, 2:24pm UTC](https://forum.ansible.com/t/ansible-vagrant-refuses-to-use-vagrant-user/14207/1 "2013-12-23T14:24:04Z")

</div>

Hi,

I have been trying to get Ansible working with Vagrant for a day or two now.

Vagrant instances are configured with a sudo enabled user, ‘vagrant’.

The auto-generated ssh config does not provide password-less access to the root account.

So I guess vagrant will have to run it’s commands using the ‘vagrant’ user account.

But when I added the ‘vvvv’ flag to debug vagrant it transpired that it was trying to use the root account.

I have spent some more time on it, and created a ticket : [https://github.com/ansible/ansible/issues/5403](https://github.com/ansible/ansible/issues/5403)

But even using Ansible from the command line, I cannot get it to perform a ssh connection using any user but root.

Has anyone else encountered a similar problem ?

Thanks,

Bryan Hunt

---

<div class="post-metadata">

**Author:** ![James\_Martin2](https://avatars.discourse-cdn.com/v4/letter/j/b9e5f3/32.png) [@James\_Martin2](https://forum.ansible.com/u/James_Martin2)\
**Post date:** [December 23, 2013, 3:38pm UTC](https://forum.ansible.com/t/ansible-vagrant-refuses-to-use-vagrant-user/14207/2 "2013-12-23T15:38:54Z")

</div>

This is how I do it:

export ANSIBLE\_REMOTE\_USER=vagrant  
export ANSIBLE\_PRIVATE\_KEY\_FILE=$HOME/.vagrant.d/insecure\_private\_key  
ssh-add $ANSIBLE\_PRIVATE\_KEY\_FILE

- James

---

<div class="post-metadata">

**Author:** ![Gilles\_Cornu](https://avatars.discourse-cdn.com/v4/letter/g/ecccb3/32.png) [@Gilles\_Cornu](https://forum.ansible.com/u/Gilles_Cornu)\
**Post date:** [December 25, 2013, 4:31pm UTC](https://forum.ansible.com/t/ansible-vagrant-refuses-to-use-vagrant-user/14207/3 "2013-12-25T16:31:42Z")

</div>

Hi Bryan,

Following [https://github.com/mitchellh/vagrant/pull/2710](https://github.com/mitchellh/vagrant/pull/2710) and [https://github.com/ansible/ansible/issues/5403](https://github.com/ansible/ansible/issues/5403), I would like to clarify a bit.

The reported problem (Why ‘–user’ argument is ignored?) affects your general usage of `ansible-playbook`. You showed that it is not a specific problem with Vagrant Ansible provisioner, so it makes sense to keep the discussion here.

That said, I would like to help you to find out the origin of this problem… But I can’t reproduce and have difficulties to figure out where could this “User=root” come from… Could you please detail your Ansible installation (from source or from package? do you use a custom ansible.cfg file?)

Cheers, Gilles

@James: exporting ANSIBLE\_REMOTE\_USER and ANSIBLE\_PRIVATE\_KEY\_FILE as you mentioned is an easy trick to be able to run `ansible-playbook` from the command line (withou --private-key and --user), but you shouldn’t need it to run commands like `vagrant provision`. Don’t you, right? Focusing on the current problem, passing a `--user` argument actually overrides this $ANSIBLE\_REMOTE\_USER variable.

---

<div class="post-metadata">

**Author:** ![Gilles\_Cornu](https://avatars.discourse-cdn.com/v4/letter/g/ecccb3/32.png) [@Gilles\_Cornu](https://forum.ansible.com/u/Gilles_Cornu)\
**Post date:** [December 26, 2013, 9:12am UTC](https://forum.ansible.com/t/ansible-vagrant-refuses-to-use-vagrant-user/14207/4 "2013-12-26T09:12:01Z")

</div>

OK, I think I’ve catched it. I can reproduce the problem when I override the remote user in the playbook file:

- hosts: all  
user: **root**

**…**

In my experience, the precedence rules for the applied ssh remote user are following:

1. `ansible_ssh_user` in inventory file (or defined as [extra variable](https://github.com/al3x/sovereign/blob/b77bcdbb0c7fa7e66d4e51e17ed88ede56614fee/Vagrantfile#L32))
2. **`user` YAML attribute in playbook file (recently discovered 😉**
3. `-u / --user` ansible-playbook argument (used by Vagrant provisioner)
4. ANSIBLE\_REMOTE\_USER environment variable
5. `remote_user` paramter in an `ansible.cfg` file
6. username of the current user  
At the moment, Vagrant behavior can therefore be shadowed by configuration 1 and 2, which is the origin of this confusion. I’ll re-open your pull request to evaluate, which strategy makes more sense…

---

<div class="post-metadata">

**Author:** ![Aleem\_Bawany](https://avatars.discourse-cdn.com/v4/letter/a/ea666f/32.png) [@Aleem\_Bawany](https://forum.ansible.com/u/Aleem_Bawany)\
**Post date:** [March 21, 2014, 7:32am UTC](https://forum.ansible.com/t/ansible-vagrant-refuses-to-use-vagrant-user/14207/5 "2014-03-21T07:32:50Z")

</div>

Sorry to revive an old thread but luckily, I came across this post only after banging my head against SSH connectivity issues for a couple of hours.

This ought to be documented somewhere but more importantly it makes sense to have the command line argument take highest precedence as that is the user’s current explicit intent when he enters the username. It would also help with quicker debugging.
