How to test your Ansible playbook with Vagrant

This page summarizes the projects mentioned and recommended in the original post on dev.to

Our great sponsors
  • WorkOS - The modern identity platform for B2B SaaS
  • InfluxDB - Power Real-Time Data Analytics at Scale
  • SaaSHub - Software Alternatives and Reviews
  • Vagrant

    Vagrant is a tool for building and distributing development environments.

  • # -*- mode: ruby -*- # vi: set ft=ruby : # Copy certificate files to destination they are expected. FileUtils.cp %w(tests/files/ca.pem tests/files/cert.pem tests/files/key.pem), 'roles/ansible-role-rethinkdb-configure/files/' FileUtils.cp %w(tests/files/vagrant1.local.net.crt tests/files/vagrant1.local.net.key), 'files/' FileUtils.cp %w(tests/files/vagrant2.local.net.crt tests/files/vagrant2.local.net.key), 'files/' FileUtils.cp %w(tests/files/vagrant3.local.net.crt tests/files/vagrant3.local.net.key), 'files/' Vagrant.configure("2") do |config| # If you have issues with SSL certificates add this config.vm.box_download_insecure = true # We want to use redhat7 as the target servers are also redhat 7 config.vm.box = "generic/rhel7" # To save overhead and time we use linked_clones (https://www.vagrantup.com/docs/providers/virtualbox/configuration#linked-clones) config.vm.provider "virtualbox" do |v| v.linked_clone = true end # We want to provision 3 servers for our cluster N = 3 (1..N).each do |machine_id| # Give the server a unique name config.vm.define "vagrant#{machine_id}" do |machine| # same for the hostname of the VM machine.vm.hostname = "vagrant#{machine_id}" # Here we will be setting up the private network for the cluster. # In this network the cluster can communicate to each other. # We also want to expose (forward) some ports that are used inside the VM to the host (so that we can connect to the dashboard) # In this example I only added it for server1. if machine_id === 1 # Private network instruction for vagrant machine.vm.network "private_network", ip: "192.168.77.#{20+machine_id}", virtualbox__intnet: "network", name: "network" # Forward all the ports below to the host. auto_correct is set to true to chose an available port if the one specified is taken machine.vm.network "forwarded_port", guest: 10082, host: 10082, auto_correct: true machine.vm.network "forwarded_port", guest: 10081, host: 10081, auto_correct: true machine.vm.network "forwarded_port", guest: 8443, host: 8443, auto_correct: true machine.vm.network "forwarded_port", guest: 9088, host: 9088, auto_correct: true machine.vm.network "forwarded_port", guest: 9089, host: 9089, auto_correct: true else # The other servers (2,3) should be in the private network machine.vm.network "private_network", ip: "192.168.77.#{20+machine_id}", virtualbox__intnet: "network" end # Only execute when all the machines are up and ready. if machine_id == N machine.vm.provision :ansible do |ansible| # Disable default limit to connect to all the machines ansible.limit = "all" # Playbook that should be executed, in this case the test playbook ansible.playbook = "tests/test.yml" # Please log it all ansible.verbose = true # We need to provied a few extra vars to the playbook ansible.extra_vars = { RETHINKDB_DATABASE_ADMIN_PASSWORD: '', NGINX_DASHBOARD_PASSWORD: 'pasword' } # These groups are the same as you normally specify in the inventorie file ansible.groups = { leader: ["vagrant1"], followers: ["vagrant2", "vagrant3"], } end end end end end

  • Ansible

    Ansible is a radically simple IT automation platform that makes your applications and systems easier to deploy and maintain. Automate everything from code deployment to network configuration to cloud management, in a language that approaches plain English, using SSH, with no agents to install on remote systems. https://docs.ansible.com.

  • I went for a golden oldie: Ansible While I had worked with it before, it was mainly putting some roles together run the script and validate, manually, that it worked.

  • WorkOS

    The modern identity platform for B2B SaaS. The APIs are flexible and easy-to-use, supporting authentication, user identity, and complex enterprise features like SSO and SCIM provisioning.

    WorkOS logo
  • RethinkDB

    The open-source database for the realtime web.

  • First off, what are we actually going to provision? We will be provisioning a 3 server cluster of a database server, RethinkDB You probably didn't heard from it before, and you can forget about it after reading this.

NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts