701-100 Exam QuestionsBrowse all questions from this exam

701-100 Exam - Question 18


An Ansible variable file contains the following content:

myapp:

option1: one

Which of the following strings can be used to reference the defined variable? (Choose two correct answers).

Show Answer
Correct Answer: ACDE

To reference a variable within a dictionary in Ansible, you can use either the bracket notation or the dot notation. In this case, you have a dictionary 'myapp' with a key 'option1'. Therefore, you can reference it using 'myapp["option1"]' or 'myapp.option1'. Both 'myapp(option1);', 'option1@myapp', and 'myapp{{option1}}' are not valid ways to reference dictionary variables in Ansible.

Discussion

3 comments
Sign in to comment
hmagrounOptions: CD
Mar 27, 2020

The correct answer is C and D see: https://docs.ansible.com/ansible/2.5/user_guide/playbooks_variables.html#what-makes-a-valid-variable-name "... YAML also supports dictionaries which map keys to values. For instance: foo: field1: one field2: two You can then reference a specific field in the dictionary using either bracket notation or dot notation: foo['field1'] foo.field1 "

hector1978Options: CD
Feb 17, 2020

This answer is wrong: The correct answer is C and D

[Removed]Options: CD
Mar 2, 2022

Ansible 2.5 documentation: YAML also supports dictionaries which map keys to values. For instance: foo: field1: one field2: two You can then reference a specific field in the dictionary using either bracket notation or dot notation: foo['field1'] foo.field1 Ansible 5 documentation: Simple variables: remote_install_path: /opt/my_app_config ... ansible.builtin.template: src: foo.cfg.j2 dest: '{{ remote_install_path }}/foo.cfg' Referencing list variables: region: "{{ region[0] }}" Dictionary variables: foo['field1'] foo.field1