Ansible Automation Ansible Collections 1 — Questions and Answers
Question 1: Which command installs an Ansible collection from Ansible Galaxy?
- ansible-galaxy collection install namespace.collection (Correct answer)
- ansible install collection namespace.collection
- ansible-collection get namespace.collection
- ansible-galaxy install --collection namespace.collection
Correct answer: ansible-galaxy collection install namespace.collection
The correct syntax is `ansible-galaxy collection install namespace.collection`, which downloads and installs the specified collection from Galaxy.
Question 2: Where are Ansible Collections stored by default when installed via ansible-galaxy for a non-root user?
- /etc/ansible/collections
- ~/.ansible/collections (Correct answer)
- /usr/share/ansible/collections
- ./collections/ansible_collections
Correct answer: ~/.ansible/collections
By default, ansible-galaxy installs collections to ~/.ansible/collections unless overridden by the COLLECTIONS_PATHS setting in ansible.cfg.
Question 3: What metadata file at the root of an Ansible Collection defines its namespace, name, version, and dependencies?
- collection.yml
- MANIFEST.json
- galaxy.yml (Correct answer)
- requirements.yml
Correct answer: galaxy.yml
galaxy.yml is the primary metadata file for an Ansible Collection and is required for building and publishing to Ansible Galaxy.
Question 4: Within an Ansible Collection's directory structure, where should custom modules be placed?
- plugins/modules/ (Correct answer)
- modules/
- library/
- roles/modules/
Correct answer: plugins/modules/
Custom modules in a collection live under plugins/modules/ because modules are treated as a plugin type in the collection layout.
Question 5: What is the correct way to reference a module from an installed collection named 'myns.mycol' in a playbook task?
- module: myns.mycol.my_module
- myns.mycol.my_module: (Correct answer)
- import_module: myns.mycol.my_module
- use_collection: myns.mycol module: my_module
Correct answer: myns.mycol.my_module:
Collection modules are referenced using the Fully Qualified Collection Name (FQCN) as the task's module key: `myns.mycol.my_module:`.
Question 6: Which file is used with `ansible-galaxy collection install -r` to install multiple collections at once?
- collections.yml
- ansible.cfg
- requirements.yml (Correct answer)
- dependencies.yml
Correct answer: requirements.yml
requirements.yml lists collections (and optionally roles) with their versions so that `ansible-galaxy collection install -r requirements.yml` can install all of them.
Question 7: In which Ansible release were Collections first introduced as a stable, supported feature?
- Ansible 2.7
- Ansible 2.8
- Ansible 2.9 (Correct answer)
- Ansible 3.0
Correct answer: Ansible 2.9
Ansible Collections became a stable feature in Ansible 2.9, replacing the older approach of bundling everything in the core Ansible package.
Which command installs an Ansible collection from Ansible Galaxy?