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
ansible
└── playbooks
└── main.yml
terraform
In main.yml
, insert the following text
---
- name: My task
hosts: all
tasks:
- name: Leaving a mark
command: "touch /tmp/ansible_was_here"
Testing
Run this to test whether ansible can reach your newly provisioned host.
ansible all -m ping
It should respond with
165.12.221.94 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python3"
},
"changed": false,
"ping": "pong"
}