9/18
Sign inSign up free

1257. One Template, Three Different Files

medium 20 XP ~12 minHands-on lab

The shop's agent reads /etc/shop/node.conf on every server. The playbook /home/student/ansible/node.yml copies the same static file everywhere, so every server claims to be web1.

The inventory (inventory.ini) has groups web (web1, web2) and db (db1). host_vars/web1.yml and host_vars/web2.yml set each web server's lb_weight; group_vars/all.yml sets db_port.

Task

Change node.yml to render a template templates/node.conf.j2 that you write, so that on every host (web1, web2, db1) /etc/shop/node.conf contains exactly these lines, in this order:

name=<the host's inventory name>
role=<web or db: the inventory group the host is in>
database=db1:5432
weight=<the host's lb_weight, or 0 if it has none>

The database line must come from the inventory and group_vars (the first host of group db, and db_port), not be typed into the template.

About this machine

Ubuntu 24.04 with no internet access and ansible-core installed. Three managed hosts sit next to it: web1, web2 and db1, separate machines with systemd and Python, reached over ssh as root. Only the ansible.builtin modules are available, and nothing can be downloaded. The grader runs your playbooks and checks the hosts' final state, not the commands you typed.

Teaching or writing about this? Embed this lab on your page

TerminalNot started

Your machine is ready to start

A fresh, isolated Ubuntu machine boots in a few seconds with the task already set up.

No account needed: 3 of 3 free tries left. Guest machines last 30 minutes.