Skip to main content
In this tutorial you’ll install Ansible on a controller VM and connect it to two target VMs. The guide assumes you have a prepared VirtualBox template VM. We will:
  • Clone the template to create one controller (AnsibleController) and two targets (target1, target2).
  • Start the VMs and determine their IP addresses.
  • Configure hostnames and SSH host keys.
  • Install ansible-core on the controller and verify connectivity using the ping module.
This flow is intentionally minimal and suitable for learning and testing. For production, use SSH keys and Ansible Vault for credentials.
  1. Clone the controller and target VMs
  • In VirtualBox, right‑click the template VM → Clone. If the Clone option is not visible, enable Expert Mode in VirtualBox Preferences.
  • Create a clone for the controller (e.g., AnsibleController) and a clone for the first target (ansible-target1). Use Linked Clone to save disk space and choose “Generate new MAC addresses”.
A desktop screenshot showing a "Clone Virtual Machine" dialog (named "ansible-target1") with options for MAC address generation and clone type. A terminal window is partially visible behind it and an Earth wallpaper fills the background.
  1. Start the controller and target VMs
  • Start the controller and target VMs from the VirtualBox UI (right-click → Start or use the toolbar).
A computer desktop shows Oracle VirtualBox Manager with a confirmation dialog asking to start virtual machines named "ansible-controller" and "ansible-target1." A terminal window is visible behind the dialog and the wallpaper is an Earth-from-space image.
  1. Find each VM’s IP address and SSH in from your host
  • On each VM, open a terminal and run ip a. Note the inet address for the VM’s network interface (for example, enp0s8):
  • From your host machine, SSH into each VM to add SSH host keys to your known_hosts and perform initial configuration:
Example controller login (shortened):
Tip: Keep sessions organized by opening separate terminal tabs (or use tmux/screen) for controller and targets.
  1. Set meaningful hostnames on each VM
  • To reduce confusion, set a readable hostname on each VM. Edit /etc/hostname and /etc/hosts.
Example on the controller:
  • Apply the change by rebooting:
  • Repeat for target1 and target2 (set /etc/hostname accordingly and update /etc/hosts).
  1. Install Ansible on the controller
A screenshot of the Ansible Community Documentation webpage, showing a left-hand navigation menu and the main content with headings like "Ansible getting started" and "Installation, Upgrade & Configuration."
A screenshot of the Ansible Community Documentation site showing the Ansible Installation Guide page, with a left navigation menu and a central list of installation topics and links.
  • For CentOS Stream 10 / RHEL-like systems, enable necessary repos and install ansible-core:
  • Verify installation:
Example output:
  1. Prepare a simple inventory and verify connectivity
  • Create a working directory and an inventory that defines your hosts. For demo convenience this example includes plaintext passwords — do not use this in production.
Storing plaintext passwords in an inventory is convenient for demos but insecure for production. Use SSH keys or Ansible Vault to protect credentials in real environments.
  • Test connectivity with the Ansible ping module:
  • If Ansible reports an sshpass error, install sshpass (used for password-based SSH in this demo):
  • Re-run the ping:
Successful response (example):
  1. Create the second target (target2) and add it to inventory
  • Clone the template again to create ansible-target2 (Linked Clone). Start it and determine its IP (for example, 192.168.0.59). From the controller, SSH once to accept the host key:
  • Update inventory.txt to include target2:
  • Run the ping against target2:
Expected response:
Note: If Ansible fails because the SSH fingerprint is unknown, manually SSH to the host from the controller to accept the fingerprint before re-running Ansible.
  1. Summary and quick reference
Table — What you did and why Key points
  • You cloned a controller and two targets, gave them meaningful hostnames, and recorded each VM’s SSH host key in known_hosts.
  • You installed ansible-core on the controller and sshpass for demo password authentication.
  • You created a basic inventory and validated connectivity with Ansible’s ping module.
Next steps (recommended)
  • Replace password authentication with SSH key-based authentication from the controller to targets.
  • Use inventory groups and host variables to scale your environment.
  • Learn Ansible Playbooks to automate configuration and tasks across your targets.
Links and references Warnings
  • Never store plaintext passwords in production inventory files.
  • Add SSH host keys manually (or manage them centrally) before automating with password-based tools like sshpass.

Watch Video