Run an Ansible Playbook on a Single Machine

This blog post will show you to run an Ansible playbook on a single machine and not a group of machines.

For use cases like this, Ansible has a few options to limit the playbook to a single machine and I will list a few. Below is an example of a host file.

[servers]
server1
server2
server3

[webservers]
server4
server5

Limit

The first option that Ansible gives us is using the –limit command lime option which will limit the playbook to run on a single machine as shown below.

ansible-playbook playbooks/git-auto-complete.yml -i hosts  --limit server4

The second option is to use -i with the hostname and a dot at the end, as shown below. Note: For this to work, the hosts’ value inside the play needs to be set to all.

ansible-playbook -i "ubuntu," user.yml 

Altogether it is recommended to use the –limit option.

Processing…
Success! You're on the list.

Posted

in

by