Where a value comes from, which source wins the 22-level precedence fight, and how facts gathered live off each box every run feed ports, paths, and the templated app.env. set_fact, registered vars, magic variables for cross-host reads, fact caching, and the hygiene that keeps it all maintainable.
7 topics
Variables are where an Ansible project earns its keep or rots. The same {{ nginx_port }} can arrive from a role default, a group_vars file, a play vars:, a set_fact, or -e on the command line — and when two of those define it, a fixed 22-level precedence decides which value the template actually sees. Get this wrong and you spend an afternoon editing a file that never wins.
Facts are the other half: the OS, the IP, the memory, the disk layout that Ansible discovers by interrogating each box live at the start of every run. There is no state file, so Ansible never recalls what web1 looked like yesterday — it asks today, and the answer is the truth. This chapter takes the Larkspur web stack and feeds its ports, paths, and templated app.env from layered variables and from facts read off the machine in real time.