Skip to content
This repository has been archived by the owner on Feb 13, 2023. It is now read-only.

drupalvm_user... ansible_ssh_user undefined #1302

Closed
jonnyeom opened this issue Apr 17, 2017 · 19 comments
Closed

drupalvm_user... ansible_ssh_user undefined #1302

jonnyeom opened this issue Apr 17, 2017 · 19 comments

Comments

@jonnyeom
Copy link

jonnyeom commented Apr 17, 2017

Issue Type

  • Bug Report / Support Request

Your Environment

Vagrant 1.9.2
VirtualBox 5.1.18r114002
Using the geerlingguy/ubuntu1204 Box

Your OS

  • Linux Ubuntu 16.04

Full console output

fatal: [mca]: FAILED! => {"failed": true, "msg": "the field 'args' has an invalid value, which appears to include a variable that is undefined. The error was: {{ drupalvm_user }}: {{ ansible_ssh_user | default(ansible_env.SUDO_USER, true) | default(ansible_env.USER, true) | default(ansible_user_id) }}: 'ansible_ssh_user' is undefined\n\nThe error appears to have been in '/vagrant/vendor/geerlingguy/drupal-vm/provisioning/roles/geerlingguy.composer/tasks/main.yml': line 37, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: Ensure composer directory exists.\n ^ here\n"}

Summary

On Vagrant Up, the provisioning errors out on the Ensure composer directory exists Task.
The error has been pasted above.

This seems to be a duplicate of an older issue, #533.
Any thoughts?

@oxyc
Copy link
Collaborator

oxyc commented Apr 17, 2017

Honestly I'm quite confused as to how this could happen. Could you hack provisioning/vars/main.yml and change

drupalvm_user: "{{ ansible_ssh_user | default(ansible_env.SUDO_USER, true) | default(ansible_env.USER, true) | default(ansible_user_id) }}"

to

drupalvm_user: "{{ ansible_ssh_user | default(ansible_env.SUDO_USER, true) | default(ansible_env.USER, true) | default(ansible_user_id, true) }}"

Does that by any chance fix it?

@jonnyeom
Copy link
Author

I am still getting the error with that change.

@oxyc
Copy link
Collaborator

oxyc commented Apr 18, 2017

Wonder if it's because you're running python3 and this is an ansible bug.

Could you install python 2 with apt install -y python-minimal and try again.

@jonnyeom
Copy link
Author

It seems that I already have that package installed.
It is strange because I have successfully provisioned this box before.

@oxyc
Copy link
Collaborator

oxyc commented Apr 18, 2017

Would you mind posting your config.yml and I'll try and reproduce this.

@oxyc
Copy link
Collaborator

oxyc commented Apr 18, 2017

Could you log in to VM and check which version of ansible is installed?

ansible/ansible#23675

@oxyc
Copy link
Collaborator

oxyc commented Apr 18, 2017

If this is indeed the issue, you can pin a specific ansible version by adding a Vagrantfile.local that contains:

config.vm.provisioners[0].config.install_mode = 'pip'
config.vm.provisioners[0].config.version = '2.2.2.0'

You might have to uninstall the existing ansible from the VM (vagrant ssh -c 'sudo apt-get remove ansible')

@oxyc
Copy link
Collaborator

oxyc commented Apr 19, 2017

Ansible 2.0 has deprecated the “ssh” from ansible_ssh_user, ansible_ssh_host, and ansible_ssh_port to become ansible_user, ansible_host, and ansible_port. If you are using a version of Ansible prior to 2.0, you should continue using the older style variables (ansible_ssh_*). These shorter variables are ignored, without warning, in older versions of Ansible.
http://docs.ansible.com/ansible/intro_inventory.html

Ansible 2.2.2.0 ansible_local provisioner

"ansible_ssh_user": "vagrant"
"ansible_user": "vagrant"
"ansible_user_id": "root"
"ansible_env.SUDO_USER": "vagrant"
"ansible_env.USER": "root"

Ansible 2.2.1.0 ansible provisioner

"ansible_ssh_user": "vagrant"
"ansible_user": "vagrant"
"ansible_user_id": "root"
"ansible_env.SUDO_USER": "vagrant"
"ansible_env.USER": "root"

Ansible 2.3.0.0 ansible_local provisioner

"ansible_ssh_user": "VARIABLE IS NOT DEFINED!"
"ansible_user": "VARIABLE IS NOT DEFINED!"
"ansible_user_id": "root"
"ansible_env.SUDO_USER": "vagrant"
"ansible_env.USER": "root"

Ansible 2.3.0.0 ansible provisioner

"ansible_ssh_user": "vagrant"
"ansible_user": "vagrant"
"ansible_user_id": "root"
"ansible_env.SUDO_USER": "vagrant"
"ansible_env.USER": "root"

So I don't think switching to ansible_user fixes this unfortunately. But we should do it either way as ansible_ssh_user is deprecated. Ran all of these on Vagrant 1.9.3

@oxyc
Copy link
Collaborator

oxyc commented Apr 19, 2017

I can confirm this bug exists when using ansible_local and Ubuntu 12.04. Doesn't happen using ansible provisioner, Ansible v2.2 or Ubuntu 16.04. It actually seems to work using Ansible 2.3 and pip as the installation method even if the ansible versions and python versions are identical. O.o

ansible 2.3.0.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = Default w/o overrides
  python version = 2.7.3 (default, Oct 26 2016, 21:01:49) [GCC 4.6.3]

@jonnyeom could you check if it works if you uninstall ansible vagrant ssh -c 'sudo apt-get remove ansible and add a Vagrantfile.local that has:

config.vm.provisioners[0].config.install_mode = 'pip'

@jonnyeom
Copy link
Author

@oxyc I uninstalled ansible and added the Vagrantfile.local and provisioning was successful.

@oxyc
Copy link
Collaborator

oxyc commented Apr 19, 2017

Great! That's some weird bug right there. I don't see a way we can fix it though. @geerlingguy should we dig deeper and see why it works with pip and not the ansible ppa on Ubuntu 12.04 or just point people to this issue if it comes up again?

@geerlingguy
Copy link
Owner

It seems this is definitely due to a change in Ansible itself, see: ansible/ansible#23530

@oxyc
Copy link
Collaborator

oxyc commented Apr 20, 2017

Also why isn't undefined being caught by |default()?

@geerlingguy
Copy link
Owner

@oxyc - It's weird... the behavior of ansible_user is confusing me since 2.3.0 was released. Someone mentioned using ansible_user_id...

@oxyc
Copy link
Collaborator

oxyc commented Apr 20, 2017

Someone mentioned using ansible_user_id...

That only returns root though.

For now, this specific bug only seem to occur when you're running Ubuntu 12.04 and ansible_local though (havent checked 14.04 but 16.04 worked fine in all scenarios). And the fix is fairly simple:

Uninstall ansible

vagrant ssh -c 'sudo apt-get remove ansible'

and add a Vagrantfile.local with

config.vm.provisioners[0].config.install_mode = 'pip'

@geerlingguy
Copy link
Owner

That sounds like a decent enough workaround. One other question, though—shouldn't

drupalvm_user: "{{ ansible_ssh_user | default(ansible_env.SUDO_USER, true) | default(ansible_env.USER, true) | default(ansible_user_id) }}"
be ansible_user and not ansible_ssh_user?

@oxyc
Copy link
Collaborator

oxyc commented Apr 20, 2017

be ansible_user and not ansible_ssh_user?

Yes, even if it wont fix the bug, it should be updated.

Also, if we depend on environment variables (which I think we probably could) this is also be fixable with:

drupalvm_user: "{{ ansible_env.SUDO_USER | default(ansible_env.USER, true) | default(ansible_user_id) }}"

If running through sudo this would return the vagrant user. If the command is running directly root will be returned. And lastly (if no environment variables are available) ansible_user_id will return the current user or the remote (root).

@geerlingguy
Copy link
Owner

@oxyc - For that change... I would want to do a little extra testing to confirm it doesn't change any existing configurations; I do think relying on the env vars would be more stable than ansible_user type variables, judging by the inconsistency in the past few releases!

oxyc added a commit to oxyc/drupal-vm that referenced this issue Apr 20, 2017
geerlingguy added a commit that referenced this issue Apr 20, 2017
Issue #1302: Remove ansible_ssh_user variable to avoid upstream bugs
@geerlingguy
Copy link
Owner

Going to tentatively mark this as fixed, as I've merged the PR. I will do a little testing really quick on prod.drupalvm.com and verify it doesn't cause any changes.

sonfd pushed a commit to sonfd/drupal-vm that referenced this issue May 19, 2017
kryptonite303 added a commit to mongodb-ansible-roles/ansible-role-build that referenced this issue Sep 9, 2019
When using ansible-local, the ansible_env.USER variable is set to root
instead of the user you're sshing as. Instead, use ansible_env.SUDO_USER
as seen here: geerlingguy/drupal-vm#1302 (comment)
r1cep added a commit to r1cep/ansible-ubuntu that referenced this issue Dec 23, 2020
ERROR:

```
The task includes an option with an undefined variable. The error was: 'ansible_user' is undefined
```

- ref. ansible/ansible#23530
- ref. geerlingguy/drupal-vm#1302
r1cep added a commit to r1cep/ansible-ubuntu that referenced this issue Dec 23, 2020
* ➕ Added fzf package in common role.

* 💚 Fixed error 'ansible_user' is undefined.

ERROR:

```
The task includes an option with an undefined variable. The error was: 'ansible_user' is undefined
```

- ref. ansible/ansible#23530
- ref. geerlingguy/drupal-vm#1302
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants