Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the Vagrant file with dynamic ANSIBLE_PATH #257

Merged
merged 1 commit into from
Jul 3, 2015
Merged

Update the Vagrant file with dynamic ANSIBLE_PATH #257

merged 1 commit into from
Jul 3, 2015

Conversation

louim
Copy link
Contributor

@louim louim commented Jul 2, 2015

ANSIBLE_PATH was relative to the folder where the command was called. This caused error when using Vagrant global commands, which can be called from anywhere. for example vagrant halt 428b9b5 would produce this error (when in another folder):

There was an error loading a Vagrantfile. The file being loaded
and the error message are shown below. This is usually caused by
a syntax error.

Path: /Users/louim/repositories/bedrock-ansible-dev/bedrock-ansible/Vagrantfile
Message: ./group_vars/development file not found. Please set `ANSIBLE_PATH` in Vagrantfile

Using __dir__ we alway get the path relative to the file itself, not the current folder where the command is executed.

ANSIBLE_PATH was relative to the folder where the command was called. This caused error when using Vagrant global commands, which can be called from anywhere.
@kalenjohnson
Copy link
Contributor

👍 haven't tested this, but I did miss being able to vagrant up and vagrant halt from whatever child directory I was in.

How would this work with using something like the roots-example-project.com project? just __dir__ + '/site' ?

@kalenjohnson
Copy link
Contributor

Whoops, I mean __dir__ + '/ansible'

@louim
Copy link
Contributor Author

louim commented Jul 2, 2015

@kalenjohnson Not exactly, it just evaluate as the full path to the folder where the Vagrantfile is. This doesn't change the current way this works. It just make it work correctly with Vagrant global commands. To do what you are trying to do you just have to use: vagrant global-status to get the id of the VM and you can run vagrant (up | provision | halt | whathever) your_vm_id from any folder.

@kalenjohnson
Copy link
Contributor

@louim actually it must be a nice side-effect, because Vagrant does traverse up folders to see if it can find a Vagrantfile. I just tested this and it does in fact work. Following this type of project: https://github.com/roots/roots-example-project.com

And changing https://github.com/roots/roots-example-project.com/blob/master/Vagrantfile#L6 to ANSIBLE_PATH = __dir__ + '/ansible', does in fact allow you to issue vagrant commands from the site folder or any child folder of the project.

So.... 👍 👍 👍 👍 👍

@louim
Copy link
Contributor Author

louim commented Jul 2, 2015

Oh, my bad, you are totally right, I hadn't see that the vagrantfile was out of the bedrock-ansible directory. Then yes it work like you mentioned.

swalkinshaw added a commit that referenced this pull request Jul 3, 2015
Update the Vagrant file with dynamic ANSIBLE_PATH
@swalkinshaw swalkinshaw merged commit 140b02d into roots:master Jul 3, 2015
@swalkinshaw
Copy link
Member

Good idea! Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants