LOGBOOK

HELP

Quiz Entry - updated: 2026.11.05

How do you read a value from a dictionary variable, and why is bracket notation the safer choice?

Use dot notation users.bjones.first_name or bracket notation users['bjones']['first_name']; both return Bob. Brackets are safer because a key that matches a Python method name (copy, add, discard, keys, …) can be misread in dot notation.

users.bjones.first_name          # 'Bob'
users['acook']['home_dir']       # '/users/acook'

Ansible variables are Python dictionaries underneath. In dot notation, something.copy could mean "the key named copy" or "the dictionary's built-in copy() method", and Jinja2 may pick the method. Bracket notation is unambiguous: ['copy'] can only be a key.

Brackets also work when a key contains characters dot notation can't handle (hyphens, spaces), and when the key itself is in a variable: users[username].

Both forms are valid. Red Hat's advice is to choose one and use it everywhere in the project, so the code reads consistently and is easier to debug.

Go deeper:

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