Ansible Automation Ansible Collections 2 — Questions and Answers
Question 1: What does the `collections:` keyword at the play or role level do in an Ansible playbook?
- Automatically installs the listed collections before the play runs
- Sets the search path so short (non-FQCN) module names resolve to those collections (Correct answer)
- Validates collection version constraints before execution
- Downloads collections from a private repository at runtime
Correct answer: Sets the search path so short (non-FQCN) module names resolve to those collections
The `collections:` keyword acts like a namespace import, telling Ansible where to search for modules and plugins referenced by short names in that play or role.
Question 2: Which command builds an Ansible Collection into a distributable .tar.gz archive?
- ansible-galaxy collection package
- ansible-galaxy collection build (Correct answer)
- ansible-galaxy collection create --build
- ansible-collection build
Correct answer: ansible-galaxy collection build
`ansible-galaxy collection build` creates a tarball (e.g., namespace-collection-1.0.0.tar.gz) in the current directory ready for publishing or offline distribution.
Question 3: How do you publish a built collection artifact to Ansible Galaxy?
- ansible-galaxy collection upload namespace-collection-1.0.0.tar.gz
- ansible-galaxy collection push namespace-collection-1.0.0.tar.gz
- ansible-galaxy collection publish namespace-collection-1.0.0.tar.gz (Correct answer)
- ansible-galaxy collection submit namespace-collection-1.0.0.tar.gz
Correct answer: ansible-galaxy collection publish namespace-collection-1.0.0.tar.gz
`ansible-galaxy collection publish <tarball>` uploads the built collection archive to Galaxy using the API token configured in ansible.cfg or via --token.
Question 4: What is the role of the auto-generated `MANIFEST.json` file inside a built Ansible Collection archive?
- It defines human-readable collection metadata for Galaxy's web UI
- It contains a file manifest with checksums used to verify collection integrity (Correct answer)
- It specifies which modules are public vs. private within the collection
- It holds license and copyright information for the collection
Correct answer: It contains a file manifest with checksums used to verify collection integrity
MANIFEST.json is generated automatically by `ansible-galaxy collection build` and contains a list of all included files along with their checksums for integrity verification.
Question 5: In an Ansible Collection, where should custom Jinja2 filter plugins be placed?
- filters/
- plugins/filter/ (Correct answer)
- lib/filters/
- templates/filters/
Correct answer: plugins/filter/
Filter plugins belong in plugins/filter/ (singular) within a collection, following the standard collection plugin directory layout.
Question 6: In the context of Ansible Collections, what does the 'namespace' part of a FQCN represent?
- A Python package namespace used internally by Ansible
- The author or organization that owns the collection, forming the first segment of the FQCN (Correct answer)
- A reserved Ansible keyword for scoping variables in a playbook
- An Ansible Tower organizational unit for access control
Correct answer: The author or organization that owns the collection, forming the first segment of the FQCN
The namespace (e.g., `community` in `community.general`) identifies the author or organization and is the first segment of every Fully Qualified Collection Name.
Question 7: How do you configure a custom collection installation path so Ansible searches it automatically?
- Set the ANSIBLE_COLLECTIONS_DIR environment variable
- Set COLLECTIONS_PATHS in ansible.cfg or the ANSIBLE_COLLECTIONS_PATHS environment variable (Correct answer)
- Pass --collections-path to every ansible-playbook command
- Edit DEFAULT_COLLECTIONS_PATH in the Ansible source code
Correct answer: Set COLLECTIONS_PATHS in ansible.cfg or the ANSIBLE_COLLECTIONS_PATHS environment variable
COLLECTIONS_PATHS in ansible.cfg (or the ANSIBLE_COLLECTIONS_PATHS env variable) defines a colon-separated list of paths Ansible searches for installed collections.
What does the `collections:` keyword at the play or role level do in an Ansible playbook?