Linux+ V8 YAML Syntax for Ansible Playbooks Quiz

Reviewed by Joshua Gelman
Joshua Gelman, CompTIA Certified |
CompTIA Expert
Review Board Member
Joshua G. is a cybersecurity specialist and instructor with over a decade of hands-on experience in incident response, secure system design, and risk management. He holds CompTIA Security+, CySA+, SecurityX (CASP+), CSAP, and CSAE certifications, as well as the CISSP, and teaches cybersecurity as an adjunct instructor at Texas A&M Engineering Extension Service (TEEX). He earned his MS in Information Science from the University of Pittsburgh.
, CompTIA Certified
By Thames
T
Thames
Community Contributor
Quizzes Created: 11982 | Total Attempts: 187,298
| Attempts: 12 | Questions: 20 | Updated: Aug 14, 2026
Please wait...
Question 1 / 21
🏆 Rank #-- ▾
0 %
0/100
Score 0/100

1. How do you reference a variable in an Ansible playbook using YAML?

Explanation

Ansible uses Jinja2 templating to evaluate variables in playbooks. Enclose a variable name in double curly braces, such as `{{ variable_name }}`, and Ansible substitutes its value when processing the playbook. The other options are not the standard syntax for referencing variables in Ansible.

Submit
Please wait...
About This Quiz
Linux+ V8 Yaml Syntax For Ansible Playbooks Quiz - Quiz

This quiz evaluates your understanding of YAML syntax and its application in Ansible playbooks. YAML is the markup language that Ansible uses to define automation tasks, making it essential for Linux professionals. Master YAML structure, indentation rules, data types, and playbook organization to effectively create and manage infrastructure automation.

2.

What first name or nickname would you like us to use?

You may optionally provide this to label your report, leaderboard, or certificate.

2. What is the correct YAML syntax for defining a boolean value?

Explanation

YAML represents booleans with unquoted literal values. In YAML 1.1, `true`/`false`, `yes`/`no`, and `on`/`off` are recognized as boolean values; YAML 1.2 standardizes `true` and `false`. Some parsers may therefore treat the other forms differently.

Submit

3. Which YAML construct is used for conditional task execution?

Explanation

In Ansible, `when:` is the directive used to control whether a task runs. It is followed by a condition, and the task executes only when that condition evaluates to true. `if:`, `condition:`, and `unless:` are not standard Ansible task keywords for conditional execution.

Submit

4. In YAML playbooks, what does 'hosts: all' specify?

Explanation

In an Ansible playbook, `hosts: all` targets every host listed in the inventory, so the play’s tasks run on all of them.

Submit

5. What does the 'register' keyword do in an Ansible task?

Explanation

The `register` keyword stores a task’s result in a named variable. Later tasks can use that variable to inspect output, check whether the task changed anything, or make decisions based on its success or failure.

Submit

6. In YAML, how do you write a multi-line string?

Explanation

YAML uses block scalar indicators to represent multi-line strings. The pipe (`|`) preserves line breaks, while the greater-than sign (`>`) folds most line breaks into spaces. Both allow readable text to span multiple lines.

Submit

7. What is the purpose of the 'become' keyword in an Ansible playbook?

Explanation

The `become` keyword enables privilege escalation for a task or play, allowing it to run as another user—commonly `root`—when administrative permissions are needed.

Submit

8. Which YAML data type represents a collection of key-value pairs?

Explanation

In YAML, a mapping stores data as key-value pairs, much like a dictionary or hash map. Each key is associated with a value, allowing related information to be organized and accessed by key.

Submit

9. In YAML, what is the difference between single and double quotes?

Explanation

Double-quoted YAML strings interpret escape sequences such as `\n` for a newline. Single-quoted strings treat backslashes literally; to represent a single quote within one, write it twice (`''`).

Submit

10. What does the 'name' field in an Ansible task do?

Explanation

The `name` field gives an Ansible task a clear, human-readable label. It appears in playbook output, making it easier to understand what each task does and to track progress during execution. It does not select the module or configure hosts or error handling.

Submit

11. What is the primary purpose of YAML in Ansible?

Explanation

YAML provides a clear, human-readable format for writing Ansible playbooks. These files describe the systems to manage and the tasks Ansible should perform, such as installing packages or configuring services.

Submit

12. In YAML, what does the '---' at the beginning of a file indicate?

Explanation

The `---` marker indicates the beginning of a YAML document. It is especially useful when a file contains multiple YAML documents, separating one document from the next.

Submit

13. Which keyword is used to run tasks sequentially on hosts in Ansible?

Explanation

In an Ansible play, the `tasks:` section lists the actions to perform. Ansible executes these tasks in the order they appear, making `tasks:` the keyword used to define sequential work on hosts.

Submit

14. What is a 'play' in an Ansible playbook?

Explanation

In Ansible, a play defines which managed hosts or host groups are targeted and the sequence of tasks to run against them. It can also include settings such as variables and handlers, but its central role is connecting a set of hosts with the work they should perform during a playbook run.

Submit

15. In YAML, how do you define a list using the flow style syntax?

Explanation

YAML flow-style lists use square brackets, with each item separated by a comma. Thus, `[item1, item2, item3]` defines a list containing three items.

Submit

16. What is the correct YAML syntax for defining a key-value pair?

Explanation

In YAML, a key-value pair is written with the key followed by a colon and a space, then the value. This mapping format is commonly used to define properties in configuration files.

Submit

17. In an Ansible playbook, what does the 'hosts' directive specify?

Explanation

The `hosts` directive identifies the inventory group or machines that Ansible will connect to and run the playbook’s tasks on.

Submit

18. Which YAML data type represents a list of items?

Explanation

In YAML, a sequence represents an ordered list of values or items. Each entry is commonly written on a separate line with a hyphen and a space, such as `- apple` and `- banana`. This differs from a dictionary, which pairs keys with values, and scalar types such as strings and booleans.

Submit

19. How many spaces should you use for indentation in YAML files?

Explanation

YAML uses spaces to show nesting and structure, and indentation must be consistent within a file. Use at least two spaces for each indentation level; tab characters are not valid for indentation and can cause parsing errors. The exact number of spaces may vary, as long as the structure is clear and consistent.

Submit

20. In YAML, what character is used to denote a comment?

Explanation

In YAML, a `#` marks the start of a comment. Any text after it on the same line is treated as a comment and is ignored when the YAML document is parsed.

Submit
×
Saved
Thank you for your feedback!
View My Results
Joshua Gelman |CompTIA Certified |
CompTIA Expert
Joshua G. is a cybersecurity specialist and instructor with over a decade of hands-on experience in incident response, secure system design, and risk management. He holds CompTIA Security+, CySA+, SecurityX (CASP+), CSAP, and CSAE certifications, as well as the CISSP, and teaches cybersecurity as an adjunct instructor at Texas A&M Engineering Extension Service (TEEX). He earned his MS in Information Science from the University of Pittsburgh.
Cancel
  • All
    All (20)
  • Unanswered
    Unanswered ()
  • Answered
    Answered ()
How do you reference a variable in an Ansible playbook using YAML?
What is the correct YAML syntax for defining a boolean value?
Which YAML construct is used for conditional task execution?
In YAML playbooks, what does 'hosts: all' specify?
What does the 'register' keyword do in an Ansible task?
In YAML, how do you write a multi-line string?
What is the purpose of the 'become' keyword in an Ansible playbook?
Which YAML data type represents a collection of key-value pairs?
In YAML, what is the difference between single and double quotes?
What does the 'name' field in an Ansible task do?
What is the primary purpose of YAML in Ansible?
In YAML, what does the '---' at the beginning of a file indicate?
Which keyword is used to run tasks sequentially on hosts in Ansible?
What is a 'play' in an Ansible playbook?
In YAML, how do you define a list using the flow style syntax?
What is the correct YAML syntax for defining a key-value pair?
In an Ansible playbook, what does the 'hosts' directive specify?
Which YAML data type represents a list of items?
How many spaces should you use for indentation in YAML files?
In YAML, what character is used to denote a comment?
play-Mute sad happy unanswered_answer up-hover down-hover success oval cancel Check box square blue
Alert!