Configuring Ansible to run commands on the provisioned resources

This is part 3 of the my series on automating my Home Lab. In this chapter, we will be integrating the inventory that was generated by terraform in the last episode.

At the end of the exercise, the repository will look something like this with these changes.

Ansible Setup

You need to install Ansible using the following steps. Check this for up to date steps

Create a python3 virtual Environment using.

cd ~/python-venvs
python3 -m virtualenv ansible

Note: I keep all my virtual environments in the same dir ~/python-venvs 2. Activate the virtual environment

source ~/python-venv/ansible/bin/activate
Install ansible using
pip install ansible
Make sure ansible is working with
ansible --version

Configure a simple ansible playbook

Not much changes are needed here, we need to create a directory structure like this

└── playbooks
    └── main.yml

In main.yml, insert the following text

- name: My task
  hosts: all
     - name: Leaving a mark
       command: "touch /tmp/ansible_was_here"


Run this to test whether ansible can reach your newly provisioned host.

ansible all -m ping

It should respond with | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python3"
    "changed": false,
    "ping": "pong"

Next Steps

Project Page

Related Posts

2 thoughts on “Configuring Ansible to run commands on the provisioned resources

Leave a Reply

%d bloggers like this: