LOGBOOK

HELP

Quiz Entry - updated: 2026.11.05

Why would you store related settings in a dictionary variable instead of separate variables like user1_first_name, user1_home_dir?

A dictionary groups all data about one thing under one name, so you don't have to encode the structure in long variable names. It is easier to read, to extend, and to loop over.

Six flat variables like user1_first_name on the left versus one nested users dictionary on the right, with both access syntaxes below

* The dictionary keeps each user's data together under one name. *

Flat variables encode the structure in the name:

user1_first_name: Bob
user1_last_name: Jones
user1_home_dir: /users/bjones
user2_first_name: Anne
user2_last_name: Cook
user2_home_dir: /users/acook

The same data as one dictionary named users:

users:
  bjones:
    first_name: Bob
    last_name: Jones
    home_dir: /users/bjones
  acook:
    first_name: Anne
    last_name: Cook
    home_dir: /users/acook

A dictionary (also "mapping" or "hash") is a set of key-value pairs, and a value can be another dictionary. Now "all users" is one variable you can pass to a loop, adding a user means adding one block, and the relationship between a first name and a home directory is visible in the structure rather than hidden in a naming convention.

Go deeper:

From Quiz: ITIA / Ansible Variables, Secrets and Facts | Updated: Nov 05, 2026