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

Use Ansible inside VM if Ansible is not present on the host #199

Closed
2 tasks done
dsnopek opened this issue Aug 14, 2015 · 11 comments
Closed
2 tasks done

Use Ansible inside VM if Ansible is not present on the host #199

dsnopek opened this issue Aug 14, 2015 · 11 comments

Comments

@dsnopek
Copy link

dsnopek commented Aug 14, 2015

Remaining Tasks

  • Add which method to Vagrantfile and use it instead of is_windows to determine whether to run windows.sh shell provisioning script.
  • Update documentation and quick start guide, and don't mention installation of Ansible/roles by default, but rather, mention that it's a best practice/better for the long run/faster.

Original Issue

In the current install instructions, you have to install ansible on the host machine and run sudo ansible-galaxy install -r provisioning/requirements.txt --force on the host. When I was first trying out drupal-vm, I actually stopped at this point because it seemed suspect and didn't want to have to install something globally on my host system. (Eventually, I came back after too many people gave recommendations to use drupal-vm ;-))

The reason is that I do everything in VMs (I have 32G of RAM and run several VMs), most using vagrant with Puppet or Chef for provisioning -- however, Puppet or Chef is installed inside the VM and nothing needs to be changed on my host system.

Would it be possible to install Ansible inside the VM so that nothing on the host system needs to be changed?

I have no experience with Ansible, so it's posible that this is how Ansible must work. However, Puppet and Chef have a "local mode" where it run directly on the local machine (rather than remotely logging into another machine and running there, which is what you'd generally do in production).

Thanks!

@cweagans
Copy link

Valkyrie does something like this: https://github.com/GetValkyrie/valkyrie

It installs Ansible inside the vm via the shell provisioner, and then runs another shell provisioner to actually run the playbooks.

Another option is to get the ansible_guest provisioner into Vagrant itself, which does exactly what you (and many other people) are looking for: hashicorp/vagrant#5340

@geerlingguy
Copy link
Owner

@dsnopek @cweagans - Ansible does work great inside the VM—in fact, if you're on one of those pesky Windows systems, that's how it is installed and used.

However, there are many advantages to running Ansible from the host machine:

  1. If, like me, you normally bring up 20-40 VMs in the course of the day, it's incredibly annoying/wasteful to have to install CM tools inside that VM prior to doing anything useful with the VM (like configuring it).
  2. Ansible (unlike the other CM tools that require extra stuff on all your managed servers) is optimized for running from a host machine, and controlling servers via SSH. So for anyone wanting to use Ansible for anything more than just managing one instance of a Vagrant VM, they'll want to have it installed on the host machine.

Additionally, you technically don't need to use sudo to install the role requirements. I just leave that there as a sensible default, since Ansible (out of the box) uses the path /etc/ansible/roles to install roles, and that requires sudo access for writes.

Just be lucky I don't (as many other projects do, for some incredibly and painfully insane reason) tell you to run curl http://random-potentially-malicious/script.sh | sudo bash ;)

You can tell Ansible to install roles anywhere you want (in /etc/ansible/ansible.cfg); on my system, I use the roles_path of ~/ansible/roles, so I don't need to use sudo, and it also works for all user accounts on the system (each user gets own copy of all the roles).

@geerlingguy
Copy link
Owner

Since you're the second person who's stated apprehension about running a command with sudo to do some of the setup process (in addition to VirtualBox and Vagrant installation requiring sudo, though through a friendly UI dialog), I may document why the example is so, and also add a page in the official docs about Ansible usage and where to get more info.

A couple relevant Ansible resources (besides the official docs):

@cweagans
Copy link

There's also a good reason to do it inside the vm: people at a training need a box to develop with, and it's easiest to do that with as few host dependencies as possible. Then again, if they're already installing vbox and vagrant, what's one more thing?

@joestewart
Copy link
Contributor

Maybe check if ansible-playbook is available instead of checking for windows? This is what phansible does: https://github.com/phansible/phansible/blob/master/Vagrantfile#L25

Would it be possible to add the roles path argument to ansible-galaxy? At one time was working on a patch for extra arguments to the vm.

@geerlingguy
Copy link
Owner

@joestewart - Hmm... that's intriguing, I could do that, and change readme/quick start guide to just mention "if you want to install and use ansible on your host machine (highly recommended), do the following..."

It's still nicer output and faster to install on host then use for every subsequent VM build, so I'm a bit torn. I hate making beginner users (who would be most likely to skip the optional host install) spend another minute or two (especially if they're on slower connections) while the VM gets Ansible installed inside.

But I'm leaning the way Phansible does it. That could be a happy medium.

@dsnopek
Copy link
Author

dsnopek commented Aug 17, 2015

Thanks everyone for all the feedback!

Part of my apprehension to this was that I don't know Ansible or use it for any of my other VMs. Since there are so many provisioning tools, and I'm as likely to use a VM created by myself (I know/use Puppet) as a VM created by someone else (could use anything), it's nice to be able to ignore which provisioning tool is used and just say "VM go now" (I mean "vagrant up") without doing anything my host system. :-)

I understand @geerlingguy's perspective, that if you have lots of VMs using Ansible, there could be some efficiencies by installing on the host system. But I would guess that isn't the case for most potential users? A "zero setup" default plus some documentation on how to make things more efficient makes more sense to me from my perspective. It could make it easier to for more new users to adopt drupal-vm at first, and then as they become used to it and want to make it better/faster, they could do more configuration.

@fubarhouse
Copy link

I see value in this one. Although it won't affect me directly, I feel that when I finally distribute my VM package I'm working on, it would be better (for my colleagues) to have less to muck around with.

@geerlingguy geerlingguy changed the title Is it possible to use Ansible in the VM so that it isn't necessary to install on the host machine? Use Ansible inside VM if Ansible is not present on the host Aug 18, 2015
@geerlingguy
Copy link
Owner

I've completed half the work for this issue... will update documentation when I get a moment later.

@dsnopek
Copy link
Author

dsnopek commented Aug 20, 2015

Cool! Thanks for addressing this. :-)

@geerlingguy
Copy link
Owner

You can now install Drupal VM on any platform even if Ansible isn't installed :)

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

5 participants