RackPeek can generate production-ready Ansible inventory directly from your modeled infrastructure.
A resource becomes an Ansible host when it has an address label.
At minimum, set:
labels:
ansible_host: 192.168.1.10
Without this, the resource will not appear in inventory.
labels:
ansible_host: 192.168.1.10
ansible_user: ubuntu
ansible_port: 22
ansible_ssh_private_key_file: ~/.ssh/id_rsa
env: prod
role: web
| Label | Purpose |
|---|---|
| ansible_host | IP or DNS target |
| ansible_user | SSH user |
| ansible_port | SSH port |
| ansible_ssh_private_key_file | SSH key |
| env | Used for grouping |
| role | Used for grouping |
Tags are simple grouping mechanisms.
Example:
tags:
- prod
- web
- ansible
If you generate inventory with:
--group-tags prod,web
You will get:
[prod]
vm-web01 ...
[web]
vm-web01 ...
Labels allow structured grouping.
Example:
labels:
env: prod
role: database
Generating with:
--group-labels env,role
Produces:
[env_prod]
vm-db01 ...
[role_database]
vm-db01 ...
This is cleaner and more scalable than raw tags.
- kind: System
type: vm
os: ubuntu-22.04
cores: 4
ram: 8
name: vm-web01
tags:
- prod
- web
labels:
ansible_host: 192.168.1.10
ansible_user: ubuntu
env: prod
role: web
rpk ansible inventory \
--group-tags prod,web \
--group-labels env,role \
--global-var ansible_user=ansible \
--global-var ansible_python_interpreter=/usr/bin/python3
Navigate to:
/ansible/inventory
Set:
Click Generate.
[all:vars]
ansible_python_interpreter=/usr/bin/python3
ansible_user=ansible
[env_prod]
vm-web01 ansible_host=192.168.1.10 ansible_user=ubuntu
[role_web]
vm-web01 ansible_host=192.168.1.10 ansible_user=ubuntu
[prod]
vm-web01 ansible_host=192.168.1.10 ansible_user=ubuntu
- name: Test production connectivity
hosts: env_prod
gather_facts: false
tasks:
- name: Ping hosts
ansible.builtin.ping:
Run:
ansible-playbook -i inventory.ini ping.yml
- name: Configure web servers
hosts: role_web
become: true
tasks:
- name: Install nginx
ansible.builtin.apt:
name: nginx
state: present
update_cache: true
- name: Ensure nginx running
ansible.builtin.service:
name: nginx
state: started
enabled: true
- name: Configure database servers
hosts: role_database
become: true
tasks:
- name: Install PostgreSQL
ansible.builtin.apt:
name: postgresql
state: present
update_cache: true
Prefer:
env: prod
role: web
Over raw tags when designing larger infrastructure.
Use:
[all:vars]
ansible_user=ansible
ansible_python_interpreter=/usr/bin/python3
Override per host only when needed.
Model:
Deploy against systems, not services.
Avoid:
Use both:
envroleThen your structure becomes:
env_prod
env_staging
role_web
role_database
This allows extremely flexible play targeting:
ansible-playbook site.yml -l env_prod
ansible-playbook site.yml -l role_web
ansible-playbook site.yml -l env_prod:&role_web
To use RackPeek effectively with Ansible:
ansible_host labelenv and role labels