QuickStartOfVagrantAndAnsible

TurnToJPG -->


Setup Environment

Using vagrant box list for getting all of the boxes, then initiate the environment via(take rhel74 box for example):

$ vagrant init rhel74

Add the cpus/memory customization values:

  config.vm.provider "libvirt" do |vb|
     vb.memory = "4096"
     vb.cpus = "4"
  end

Disable the rsync folder:

  config.vm.synced_folder ".", "/vagrant", disabled: true, type: "rsync", rsync__args: ['--verbose', '--archive', '--delete', '-z'] , rsync__exclude: ['.git','venv']

Add ansible deployment:

  config.vm.provision "ansible" do |ansible|
    ansible.playbook = "playbook.yml"
    ansible.become = true
  end

your playbook.yml should like following:

---
- hosts: all
  gather_facts: false
  become: True
  tasks:
    - name: "Run shell for provision"
      shell: mkdir -p /root/tttt

Manually Run ansible playbook

vagrant will create the inventory files under the .vagrant folder:

cat .vagrant/provisioners/ansible/inventory/vagrant_ansible_inventory 
# Generated by Vagrant

default ansible_host=192.168.121.215 ansible_port=22 ansible_user='vagrant' ansible_ssh_private_key_file='/media/sda/Code/vagrant/dockerOnrhel74/.vagrant/machines/default/libvirt/private_key'

Then you could run the provision task like:

$ ansible-playbook -i .vagrant/provisioners/ansible/inventory/vagrant_ansible_inventory playbook.yml