Inspired by Maxim Chernyak's blog post 6 practices for super smooth Ansible experience
The goal is to produce the convenient local playground, but skipping the ssh key insertion (Vagrant does that for us) and editing /etc/hosts (not available on Windows) while still allowing full access to the guest VMs.
Makefile is all you need. Everything else can be downloaded automatically, or use your own personal versions.
Download the Makefile, then
make Vagrantfile all
or
vagrant init centos/7; make all
make alldoes the following:make upBrings up all Vagrant boxes (same asvagrant up)make rolesInstall Ansible Galaxy roles from "requirements.yml" or "config/requirements.yml"make .vai/ssh-configCreate ssh configurationmake .vai/inventoryCreate ansible inventorymake ansible.cfgCreate default ansible.cfgmake mainRun main.yml playbook, if presentmake ipDisplay the IPs of all the VMs*
Other commands:
make VagrantfileDownloads sampleVagrantfileandGUESTS.rbmake GUESTS.rbDownloads sampleGUESTS.rb(used by sampleVagrantfile)make clean-rolesRemoves installed ansible rolesmake cleanRemoves ansible filesmake copyrightDisplays copyright informationmake etc-hostsAdd host records to all guestsmake licenseDisplays license informationmake roles-forceUpdate all roles, overwriting when requiredmake pingPings all guests via Ansible's ping modulemake pythonInstalls python on Alpine/Debian/Ubuntu systems*make root-keyCopies vagrant ssh key for root user accessmake updateDownloads latest version from GitHub*make versionDisplays installed version
- Uses a provided or downloaded
Vagrantfileto create the application stack systems. SeeVagrantfile.sampleandGUESTS.rb.samplefor a starting point. - Install any required Galaxy roles (optional)
- Write the ssh configuration (as provided by Vagrant)
- Create
ansible.cfgthat uses the above ssh configuration
Your Ansible playbooks can now access the Vagrant VMs as if they were a part of your infrastructure, either by name or by group.
The Makefile will accept command line options, or read from similarly named environmental variables:
ETC_HOSTSetc-hosts playbook*INVENTORYansible inventory file*MAINdefault playbook to run, if presentREPOupstream repositoryRETRYPATHdirectory to place retry files*ROLES_PATHansible roles pathSAMPLEVAGRANTFILEupstream Vagrantfile.sampleSSHCONFIGlocation of generated ssh configuration*VAIDIRdirectory to place Ansible files*VAULTPASSWORDFILEpath to ansible vault password file*
If requirements.yml or config/requirements.yml exists, the listed roles
will be downloaded from Galaxy. If both exist, then requirements.yml will
take precedence.
Manually installed roles can be added to the roles-local directory.
The inventory will group related hosts into groups. Related hosts all share
the same prefix. web-1, web-2, web-3 will all be a part of [web].
Update all guests' /etc/hosts with all other guests' internal networking IPs
to allow name-based addressing without relying on external DNS.
See README.Vagrantfile.
This project follows SemVer.
The ip target may fail on non-Linux guests.
The update target will overwrite the Makefile.
The etc-hosts target works best when there is only one additional interface.
Certain variables, ETC_HOSTS, INVENTORY, ROLES_PATH, SSHCONFIG,
VAIDIR, and VAULTPASSWORDFILE will break if there is embedded whitespace.