<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://charlesreid1.com/w/index.php?action=history&amp;feed=atom&amp;title=Ansible%2FFull_Stack_Playbook%2FVagrant_Setup</id>
	<title>Ansible/Full Stack Playbook/Vagrant Setup - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://charlesreid1.com/w/index.php?action=history&amp;feed=atom&amp;title=Ansible%2FFull_Stack_Playbook%2FVagrant_Setup"/>
	<link rel="alternate" type="text/html" href="https://charlesreid1.com/w/index.php?title=Ansible/Full_Stack_Playbook/Vagrant_Setup&amp;action=history"/>
	<updated>2026-06-20T05:08:27Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.39.12</generator>
	<entry>
		<id>https://charlesreid1.com/w/index.php?title=Ansible/Full_Stack_Playbook/Vagrant_Setup&amp;diff=25617&amp;oldid=prev</id>
		<title>Admin: Created page with &quot;{{Main|Ansible/Full Stack Playbook}}  This page covers how to set up Vagrant machines to test out the example playbook at Ansible/Full Stack Playbook.  =Full Stack Playboo...&quot;</title>
		<link rel="alternate" type="text/html" href="https://charlesreid1.com/w/index.php?title=Ansible/Full_Stack_Playbook/Vagrant_Setup&amp;diff=25617&amp;oldid=prev"/>
		<updated>2018-12-07T18:17:02Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;{{Main|Ansible/Full Stack Playbook}}  This page covers how to set up Vagrant machines to test out the example playbook at &lt;a href=&quot;/wiki/Ansible/Full_Stack_Playbook&quot; title=&quot;Ansible/Full Stack Playbook&quot;&gt;Ansible/Full Stack Playbook&lt;/a&gt;.  =Full Stack Playboo...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{Main|Ansible/Full Stack Playbook}}&lt;br /&gt;
&lt;br /&gt;
This page covers how to set up Vagrant machines to test out the example playbook at [[Ansible/Full Stack Playbook]].&lt;br /&gt;
&lt;br /&gt;
=Full Stack Playbook: Vagrant Setup=&lt;br /&gt;
&lt;br /&gt;
==Vagrant multi-machine setup==&lt;br /&gt;
&lt;br /&gt;
Here we walk through how to get set up with [[Vagrant]] before writing and testing the playbook.&lt;br /&gt;
&lt;br /&gt;
Note: before running any vagrant boxes, destroy and clean up prior boxes via&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vagrant destroy ---force&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Vagrantfile===&lt;br /&gt;
&lt;br /&gt;
Create a Vagrantfile with 3 hosts:&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;&amp;lt;code&amp;gt;Vagrantfile&amp;lt;/code&amp;gt;&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
VAGRANTFILE_API_VERSION = &amp;quot;2&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|&lt;br /&gt;
&lt;br /&gt;
  # Use the same key for each machine&lt;br /&gt;
  config.ssh.insert_key = false&lt;br /&gt;
&lt;br /&gt;
  config.vm.define &amp;quot;vagrant1&amp;quot; do |vagrant1|&lt;br /&gt;
    vagrant1.vm.box = &amp;quot;ubuntu/xenial64&amp;quot;&lt;br /&gt;
    vagrant1.vm.network &amp;quot;forwarded_port&amp;quot;, guest: 80, host: 8080&lt;br /&gt;
    vagrant1.vm.network &amp;quot;forwarded_port&amp;quot;, guest: 443, host: 8443&lt;br /&gt;
  end&lt;br /&gt;
  config.vm.define &amp;quot;vagrant2&amp;quot; do |vagrant2|&lt;br /&gt;
    vagrant2.vm.box = &amp;quot;ubuntu/xenial64&amp;quot;&lt;br /&gt;
    vagrant2.vm.network &amp;quot;forwarded_port&amp;quot;, guest: 80, host: 8081&lt;br /&gt;
    vagrant2.vm.network &amp;quot;forwarded_port&amp;quot;, guest: 443, host: 8444&lt;br /&gt;
  end&lt;br /&gt;
  config.vm.define &amp;quot;vagrant3&amp;quot; do |vagrant3|&lt;br /&gt;
    vagrant3.vm.box = &amp;quot;ubuntu/xenial64&amp;quot;&lt;br /&gt;
    vagrant3.vm.network &amp;quot;forwarded_port&amp;quot;, guest: 80, host: 8082&lt;br /&gt;
    vagrant3.vm.network &amp;quot;forwarded_port&amp;quot;, guest: 443, host: 8445&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that without &amp;lt;code&amp;gt;config.ssh.insert_key=false&amp;lt;/code&amp;gt; each machine would use its own SSH key, which would be a bit of a headache. With this directive, we can define a single SSH key in our ansible config file.&lt;br /&gt;
&lt;br /&gt;
===Ansible config file===&lt;br /&gt;
&lt;br /&gt;
Now the &amp;lt;code&amp;gt;ansible.cfg&amp;lt;/code&amp;gt; file should be modified to configure Ansible. Most important is the location of the private key:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[defaults]&lt;br /&gt;
inventory = inventory&lt;br /&gt;
remote_user = vagrant&lt;br /&gt;
private_key_file = ~/.vagrant.d/insecure_private_key&lt;br /&gt;
host_key_checking = False&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Run vagrant===&lt;br /&gt;
&lt;br /&gt;
Run the vagrant machines with&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vagrant up&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
See details about SSH ports using&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vagrant ssh-config&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
which will output something like this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Host vagrant1&lt;br /&gt;
  HostName 127.0.0.1&lt;br /&gt;
  User vagrant&lt;br /&gt;
  Port 2222&lt;br /&gt;
  UserKnownHostsFile /dev/null&lt;br /&gt;
  StrictHostKeyChecking no&lt;br /&gt;
  PasswordAuthentication no&lt;br /&gt;
  IdentityFile /Users/lorin/.vagrant.d/insecure_private_key&lt;br /&gt;
  IdentitiesOnly yes&lt;br /&gt;
  LogLevel FATAL&lt;br /&gt;
&lt;br /&gt;
Host vagrant2&lt;br /&gt;
  HostName 127.0.0.1&lt;br /&gt;
  User vagrant&lt;br /&gt;
  Port 2200&lt;br /&gt;
  UserKnownHostsFile /dev/null&lt;br /&gt;
  StrictHostKeyChecking no&lt;br /&gt;
  PasswordAuthentication no&lt;br /&gt;
  IdentityFile /Users/lorin/.vagrant.d/insecure_private_key&lt;br /&gt;
  IdentitiesOnly yes&lt;br /&gt;
  LogLevel FATAL&lt;br /&gt;
&lt;br /&gt;
Host vagrant3&lt;br /&gt;
  HostName 127.0.0.1&lt;br /&gt;
  User vagrant&lt;br /&gt;
  Port 2201&lt;br /&gt;
  UserKnownHostsFile /dev/null&lt;br /&gt;
  StrictHostKeyChecking no&lt;br /&gt;
  PasswordAuthentication no&lt;br /&gt;
  IdentityFile /Users/lorin/.vagrant.d/insecure_private_key&lt;br /&gt;
  IdentitiesOnly yes&lt;br /&gt;
  LogLevel FATAL&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Create Ansible inventory file===&lt;br /&gt;
&lt;br /&gt;
Once we know the SSH port for each machine, we can create an inventory file.&lt;br /&gt;
&lt;br /&gt;
A basic &amp;lt;code&amp;gt;playbook/hosts&amp;lt;/code&amp;gt; file would contain:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vagrant1 ansible_host=127.0.0.1 ansible_port=2222&lt;br /&gt;
vagrant2 ansible_host=127.0.0.1 ansible_port=2200&lt;br /&gt;
vagrant3 ansible_host=127.0.0.1 ansible_port=2201&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This, together with the playbook, tells Ansible how to reach and how to connect to each of the remote hosts. Now we can run a test command on the machines with Ansible:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ansible vagrant2 -a &amp;quot;ip addr show dev eth0&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Group the Ansible hosts file===&lt;br /&gt;
&lt;br /&gt;
As the hosts file gets more complicated, we may want to perform actions only on a group of machines. Toward this purpose we can group the machines under &amp;lt;code&amp;gt;[headings]&amp;lt;/code&amp;gt; that indicate they are part of a group.&lt;br /&gt;
&lt;br /&gt;
If we added many more hosts to the hosts file, we would want to group the Vagrant machines, so the host file would look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ontario.example.com&lt;br /&gt;
newhampshire.example.com&lt;br /&gt;
maryland.example.com&lt;br /&gt;
virginia.example.com&lt;br /&gt;
newyork.example.com&lt;br /&gt;
quebec.example.com&lt;br /&gt;
rhodeisland.example.com&lt;br /&gt;
&lt;br /&gt;
[vagrant]&lt;br /&gt;
vagrant1 ansible_host=127.0.0.1 ansible_port=2222&lt;br /&gt;
vagrant2 ansible_host=127.0.0.1 ansible_port=2200&lt;br /&gt;
vagrant3 ansible_host=127.0.0.1 ansible_port=2201&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Note on inventory files===&lt;br /&gt;
&lt;br /&gt;
Inventory files can define a number of parameters for each host. Above, we define the host and port, but other variables are also available:&lt;br /&gt;
&lt;br /&gt;
* ansible_host&lt;br /&gt;
* ansible_port&lt;br /&gt;
* ansible_user&lt;br /&gt;
* ansible_password&lt;br /&gt;
* ansible_private-key_file&lt;br /&gt;
* ansible_shell_type&lt;br /&gt;
* ansible_python_interpreter&lt;br /&gt;
&lt;br /&gt;
(But apparently only ansible_port, ansible_user, ansible_private_key_file,and ansible_shell_type can be changed in Ansible config file???)&lt;br /&gt;
&lt;br /&gt;
===Next steps===&lt;br /&gt;
&lt;br /&gt;
We will modify this inventory file as needed for the actual full stack application, but this gets you going with a basic multi-machine Vagrantfile.&lt;/div&gt;</summary>
		<author><name>Admin</name></author>
	</entry>
</feed>