Run Ansible Playbooks On Your Localhost Machine

In this post, I will show you how to run Ansible playbooks on your localhost machine only which will help test Ansible with a very basic setup.


When you don’t have access to a managed machine, you can use your Ansible host to run playbooks against itself. This is also good for learning purposes.

The process is not complicated and works very well. To get it done, all we need to do is create an inventory file or use an existing one and add our localhost, as shown below.

Inventory File

Below is my inventory file, which has a host group called mylocalhost. I also have my localhost listed as a managed host, and the most important part I tell Ansible is a local connection.

localhost ansible_connection=local

Once the inventory file and configuration are in place I can run any playbook or a single command using the following command.

ansible mylocalhost -m ping -i servers

If you need to install Ansible on Ubuntu 20.04check this post.

Success! You're on the list.