Free Ansible Playbooks Questions and Answers — Questions and Answers
Question 1: Which order does the Ansible Playbook execute?
- Playbook->Play->Task->Tasks
- Playbook->Play->Tasks->Task (Correct answer)
- Playbook->Tasks->Play-Task
- Play->Playbook->Tasks->Task
Correct answer: Playbook->Play->Tasks->Task
An Ansible playbook is the highest-level organizational unit. A playbook contains one or more 'plays', each targeting a specific group of hosts. Within each play, there is a list of 'tasks', which are individual actions to be performed. Each 'task' then calls an Ansible module to execute a specific operation on the target host(s).
Question 2: What language is the default in which Ansible playbooks are written?
- HTML
- XML
- YAML (Correct answer)
- JSON
Correct answer: YAML
Ansible playbooks are written in YAML (YAML Ain't Markup Language). YAML is a human-friendly data serialization standard often used for configuration files due to its readability and straightforward syntax. This makes playbooks easy to read, write, and understand for defining automation workflows.
Question 3: What language is the default in which Ansible playbooks are written?
- JSON format
- YAML format (Correct answer)
- HTML format
- XML format
Correct answer: YAML format
Ansible playbooks are written in YAML (YAML Ain't Markup Language) format by default. YAML is chosen for its human-readable syntax, which makes playbooks easy to write, understand, and maintain. This declarative language allows users to define the desired state of their infrastructure and the tasks to achieve it in a clear and concise manner.
Question 4: Which command will you use to run a playbook called install.yaml with Ansible?
- ansible install.yml
- ansible-playbook install.yml (Correct answer)
- ansible -p install.yml
- ansible --playbook install.yml
Correct answer: ansible-playbook install.yml
To execute an Ansible playbook, the specific command `ansible-playbook` is used, followed by the name of the playbook file. This command instructs Ansible to parse the playbook, connect to the managed hosts, and run the defined tasks in the specified order. The `ansible` command alone is typically reserved for running ad-hoc commands or single tasks, not full playbooks.
Question 5: Which argument will you use in your Ansible playbook to define a variable?
- -E (Correct answer)
- -V
- -A
- -C
Correct answer: -E
In Ansible, while variables are commonly defined using the `vars:` keyword directly within a playbook, command-line arguments can also be used to pass variables. The `-e` or `--extra-vars` argument is typically used for this purpose, allowing users to define or override variables when running a playbook. If `-E` is interpreted as a variant or typo for this command-line functionality, it serves to inject variable values into the playbook's execution context.
Question 6: Unlike any other system currently, Ansible playbooks provide the foundation of a multi-machine deployment and a straightforward configuration management solution ideal for deploying complicated applications.
- TRUE (Correct answer)
- FALSE
Correct answer: TRUE
Ansible playbooks are indeed a cornerstone for multi-machine deployments and configuration management. They provide a declarative way to define the desired state of systems across an entire infrastructure, simplifying the deployment of complex applications. This capability allows for consistent and efficient automation, making Ansible a powerful tool for managing diverse environments.
Question 7: What does the Ansible playbook phrase "become: yes" mean?
- It means that the worker node should become a manager node.
- It means that we would run all commands as root (Correct answer)
- It means that the command must be retried until it succeeds.
- It means that the service needs to be started once installed
Correct answer: It means that we would run all commands as root
The `become: yes` directive in an Ansible playbook or task means that the commands within that task or playbook will be executed with elevated privileges. This is equivalent to using `sudo` on Linux/Unix systems, allowing Ansible to perform actions that require administrative permissions. It is crucial for tasks like installing software, modifying system configurations, or managing services.
Which order does the Ansible Playbook execute?