YAML Fundamentals for Ansible Automation Quiz

Assess your understanding of YAML syntax, structure, and common practices as applied in automation playbooks. This quiz helps enhance YAML-related skills for configuring tasks and variables efficiently in automation workflows.

  1. YAML File Extension

    Which file extension is most commonly used for YAML files in automation scripts?

    1. .json
    2. .yml
    3. .xml
    4. .txt

    Explanation: .yml is a widely used file extension for YAML files, especially in automation contexts. .json and .xml are used for different data formats, not for YAML. While .txt can technically be used, it does not indicate the file is a YAML file. Using the proper extension ensures clear identification and compatibility.

  2. YAML Key-Value Separator

    In a YAML file, which character is used to separate keys from values, as in 'name: server1'?

    1. -
    2. :
    3. =
    4. ;

    Explanation: A colon (:) separates keys from values in YAML, as shown in 'name: server1'. An equal sign (=) and a dash (-) are not valid separators for key-value pairs. The semicolon (;) is also incorrect; it is not used to assign values to keys in YAML.

  3. Indentation in YAML

    What is the correct way to indicate nesting (hierarchical relationships) in YAML?

    1. By using curly braces
    2. By adding tabs for indentation
    3. By separating with commas
    4. By using consistent spaces for indentation

    Explanation: YAML uses consistent spaces to indicate nested structure; this is crucial for parsing and correctness. Using curly braces and commas is a feature of other data formats like JSON, not YAML. Tabs are not recommended because they can cause parsing errors in most YAML parsers.

  4. YAML List Syntax

    How do you start an item in a list within a YAML file?

    1. With a dash and a space
    2. With a semicolon
    3. With an asterisk
    4. With a plus sign

    Explanation: YAML lists are created by using a dash followed by a space in front of each item, such as '- item1'. An asterisk, semicolon, or plus sign are not used for listing items. Using the correct syntax helps distinguish list elements from other structures.

  5. String Values in YAML

    Which of the following represents a string value correctly assigned to a key in YAML?

    1. username=admin
    2. username:admin
    3. username: admin
    4. username admin

    Explanation: In YAML, a colon and space separate the key from its value, as shown in 'username: admin'. 'username admin' lacks the necessary colon, 'username=admin' uses an incorrect separator, and 'username:admin' is missing the space after the colon, which can cause parsing issues.

  6. Comments in YAML

    What symbol is used to start a comment in a YAML file?

    1. --
    2. @
    3. //
    4. #

    Explanation: The hash symbol (#) is used to begin comments in YAML files, making everything after it on the line ignored by the parser. Double slashes (//) and double dashes (--) are not valid for comments in YAML. The at symbol (@) has no special meaning for comments.

  7. Boolean Values in YAML

    Which of the following is a valid Boolean value in YAML?

    1. yesplease
    2. YTRUE
    3. true
    4. enabled

    Explanation: The lowercase word 'true' is a valid Boolean value in YAML. 'yesplease' is not recognized as a Boolean, 'enabled' is commonly used as a string, and 'YTRUE' is not a standard Boolean term in YAML.

  8. YAML Array Representation

    Which YAML snippet correctly defines a list of users named Alice, Bob, and Carol?

    1. users: [Alice; Bob; Carol]
    2. users: {Alice; Bob; Carol}
    3. users: Alice, Bob, Carol
    4. - Alicen- Bobn- Carol

    Explanation: The correct way to create a YAML list is by starting each item with '- ', as in the first option. Using commas, curly braces, or semicolons does not follow YAML list conventions and may cause errors during parsing.

  9. Empty Values in YAML

    How should an empty or null value be represented in YAML?

    1. key = none
    2. key: u003Cnullu003E
    3. key: {}
    4. key:

    Explanation: Leaving a key without a value, as in 'key: ', is an accepted way to represent a null value in YAML. 'key = none' uses an incorrect assignment operator, 'key: {}' defines an empty map, and 'key: u003Cnullu003E' is not standard YAML syntax.

  10. Order of Keys in YAML

    Do mappings (dictionaries) in YAML guarantee the order of keys as written in the file?

    1. Yes
    2. No
    3. Only if marked as ordered
    4. Only if sorted alphabetically

    Explanation: YAML mappings do not guarantee the order of keys unless specifically handled by a tool supporting ordered mappings. 'Yes' is incorrect because order is not maintained by default, and sorting or marking as ordered are not standard features of YAML mappings. Understanding this prevents unexpected results in automation tasks.