Vagrant create ansible

Vagrant is a Configuration management tool. In this tutorial, I will use Vagrant to create an Ansible practice environment. Quickstart Vagrant create ansible your environment developer.

Vagrant create ansible

Install the plugin for Vagrant

$ vagrant plugin install vagrant-hosts
$ vagrant plugin install vagrant-host-shell
$ vagrant plugin install vagrant-vbguest
$ vagrant plugin list
  • vagrant-hosts: Enable name resolution between guests
  • vagrant-host-shell: Make the host’s shell command executable in Vagrantfile
  • vagrant-vbguest: For shared folder (automatic installation of VirtualBox Guest Additions on the guest)

Working folder for Ansible

$ mkdir -p vagrant-ansible/ansible
$ cd vagrant-ansible
$ vagrant init -m centos/7

Note: I will use vagrant init -m to create a simple Vagrantfile


I will create an Ansible controller and servers.

Vagrant.configure("2") do |config|

  config.vm.define :ansible_controller do |ansible_controller| = "centos/7"
    ENV["LC_ALL"] = "en_US.UTF-8"
    config.ssh.insert_key = false
	ansible_controller.vm.synced_folder "./ansible", "/home/vagrant/ansible", type: "rsync" "private_network", ip: "", :netmask => ""
    ansible_controller.vm.provision :hosts, :sync_hosts => true
    ansible_controller.vm.provision :host_shell do |host_shell|
      host_shell.inline = 'scp -i ~/.vagrant.d/insecure_private_key -o "StrictHostKeyChecking no" ~/.vagrant.d/insecure_private_key vagrant@'
    ansible_controller.vm.provision "shell", inline: <<-SHELL
      chmod 600 /home/vagrant/.ssh/id_rsa
      timedatectl set-timezone asia/ho_chi_minh
      yum install -y epel-release
      yum -y update
      yum -y install python36 python36-libs python36-devel
      python36 -m ensurepip
      /usr/bin/pip3 install --upgrade pip
      /usr/bin/pip3 install ansible

  (1..N).each do |i|
    config.vm.define "server#{i}" do |server| = "centos/7"
      config.ssh.insert_key = false "private_network", ip: "192.168.3.#{i}", :netmask => ""
      server.vm.provision :hosts, :sync_hosts => true


Start vagrant

$ vagrant up
$ vagrant ssh ansible_controller
$ vagrant ssh server1
$ vagrant ssh server2

The output terminal ansible install in ansible_controller as below

$ vagrant ssh ansible_controller
Last login: Thu Apr 18 14:27:27 2019 from
[vagrant@ansible_controller ~]$ ansible --version
ansible 2.7.10
  config file = None
  configured module search path = ['/home/vagrant/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.6/site-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 3.6.6 (default, Mar 29 2019, 00:03:27) [GCC 4.8.5 20150623 (Red Hat 4.8.5-36)]
[vagrant@ansible_controller ~]$

Initial setting of Ansible

Create a file ansible.cfg in the folder ansible as in the example below

$ cat ./ansible/ansible.cfg

The content as below

inventory = ./hosts
forks = 15
host_key_chcking = False
gathering = smart

Create file hosts inventory as below

$ cat ./ansible/hosts

The content hosts file as below


Try running Ansible

$ vagrant ssh ansible_controller
[vagrant@ansible_controller ~]$ ansible -i ansible/hosts server1 -m ping
[vagrant@ansible_controller ~]$ ansible -i ansible/hosts server2 -m ping

As the picture below

Vagrant create ansible


You have to use Vagrant create ansible. I hope will this your helpful. Thank you for reading the DevopsRoles page!

About HuuPV

My name is Huu. I love technology and especially Devops Skill such as Docker, vagrant, git so forth. I likes open-sources. so I created site to share the knowledge that I have learned. My Job: IT system administrator. Hobbies: summoners war game, gossip.
View all posts by HuuPV →

3 thoughts on “Vagrant create ansible

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.