Vagrant OEL 8 DevOps · Ansible · Provisioning

VagrantAnsible Provisioning for OEL 8

Provision OEL 8 Vagrant VMs with Ansible playbooks. Use ansible or ansible_local mode, configure multi-machine inventory and install MySQL automatically.

Vagrant integrates with Ansible to provision OEL 8 VMs using playbooks. Instead of shell scripts, you write clean, idempotent Ansible playbooks that install and configure MySQL, Oracle, and ProxySQL on your VMs automatically during vagrant up.

ModeHow it worksRequirement
ansibleAnsible runs on HOST machine — connects to VM via SSHAnsible installed on HOST
ansible_localAnsible runs INSIDE the VMAnsible installed inside VM (auto-installed)
Ruby — Ansible Host Mode
Vagrant.configure("2") do |config|
  config.vm.box = "generic/oracle8"
  config.vm.network "private_network", ip: "192.168.56.10"

  config.vm.provision "ansible" do |ansible|
    ansible.playbook       = "ansible/site.yml"
    ansible.inventory_path = "ansible/inventory"
    ansible.limit          = "all"
    ansible.verbose        = "v"

    # Extra variables
    ansible.extra_vars = {
      mysql_root_password: "Root@123!",
      mysql_version: "8.0"
    }
  end
end
Ruby — Ansible Local Mode
Vagrant.configure("2") do |config|
  config.vm.box = "generic/oracle8"
  config.vm.network "private_network", ip: "192.168.56.10"

  # Share ansible folder into VM
  config.vm.synced_folder "./ansible", "/vagrant/ansible"

  config.vm.provision "ansible_local" do |ansible|
    ansible.playbook     = "ansible/site.yml"
    ansible.install      = true        # Auto-install Ansible in VM
    ansible.install_mode = "pip3"      # Use pip to install Ansible
    ansible.version      = "latest"

    ansible.extra_vars = {
      mysql_root_password: "Root@123!"
    }
  end
end
INI — Ansible Inventory
# ansible/inventory

[db_masters]
master ansible_host=192.168.56.11 ansible_user=vagrant ansible_private_key_file=.vagrant/machines/master/virtualbox/private_key

[db_replicas]
replica1 ansible_host=192.168.56.12 ansible_user=vagrant ansible_private_key_file=.vagrant/machines/replica1/virtualbox/private_key
replica2 ansible_host=192.168.56.13 ansible_user=vagrant ansible_private_key_file=.vagrant/machines/replica2/virtualbox/private_key

[proxysql]
proxysql ansible_host=192.168.56.10 ansible_user=vagrant ansible_private_key_file=.vagrant/machines/proxysql/virtualbox/private_key

[all:vars]
ansible_python_interpreter=/usr/bin/python3
YAML — MySQL Playbook
# ansible/site.yml
---
- name: Install MySQL 8 on OEL 8
  hosts: all
  become: yes
  vars:
    mysql_root_password: "Root@123!"
    mysql_version: "8.0"

  tasks:
    - name: Import MySQL GPG key
      rpm_key:
        state: present
        key: https://repo.mysql.com/RPM-GPG-KEY-mysql-2022

    - name: Install MySQL repository
      dnf:
        name: https://dev.mysql.com/get/mysql80-community-release-el8-9.noarch.rpm
        state: present
        disable_gpg_check: yes

    - name: Disable default MySQL module
      command: dnf module disable -y mysql
      changed_when: false

    - name: Install MySQL server
      dnf:
        name: mysql-community-server
        state: present

    - name: Start and enable MySQL
      systemd:
        name: mysqld
        state: started
        enabled: yes

    - name: Get temporary MySQL root password
      shell: grep "temporary password" /var/log/mysqld.log | awk "{print $NF}"
      register: temp_password
      changed_when: false

    - name: Set MySQL root password
      shell: |
        mysql --connect-expired-password -u root -p"{{ temp_password.stdout }}"           -e "ALTER USER 'root'@'localhost' IDENTIFIED BY '{{ mysql_root_password }}';"
      ignore_errors: yes

    - name: Configure MySQL root remote access
      mysql_user:
        name: root
        host: "%"
        password: "{{ mysql_root_password }}"
        priv: "*.*:ALL,GRANT"
        state: present
        login_user: root
        login_password: "{{ mysql_root_password }}"
Ruby — Multi-Machine Ansible
Vagrant.configure("2") do |config|
  config.vm.box = "generic/oracle8"

  config.vm.define "master" do |node|
    node.vm.network "private_network", ip: "192.168.56.11"

    node.vm.provision "ansible" do |ansible|
      ansible.playbook   = "ansible/mysql_master.yml"
      ansible.extra_vars = { server_id: 1, role: "master" }
    end
  end

  config.vm.define "replica1" do |node|
    node.vm.network "private_network", ip: "192.168.56.12"

    node.vm.provision "ansible" do |ansible|
      ansible.playbook   = "ansible/mysql_replica.yml"
      ansible.extra_vars = {
        server_id: 2,
        role: "replica",
        master_ip: "192.168.56.11"
      }
    end
  end
end
💡 Note: Use ansible_local when you do not have Ansible installed on your host machine (e.g. Windows) — Vagrant will automatically install Ansible inside the VM and run the playbook from there.