Explore key concepts and functions of Ansible modules with these essential questions designed to strengthen your understanding of automation tasks, module usage, and best practices in configuration management.
Which of the following describes the main purpose of an Ansible module?
Explanation: Ansible modules are reusable, task-based units that automate specific tasks such as installing packages or managing files. The other options do not accurately describe modules: visual scripting is not performed by modules, modules are not user interfaces, and they are not middleware for database connections.
If you want to ensure a file named 'example.txt' exists in a directory, which Ansible module should you use?
Explanation: The 'file' module is used to manage the presence, absence, and properties of files on the target system. 'service' is for managing services, 'yum' for package management, and 'user' for managing user accounts, which do not relate to file presence.
What does it mean when an Ansible module is idempotent?
Explanation: Idempotency ensures that repeating a task does not alter the system after achieving the desired state. Manual confirmation and interactive-only use go against automation principles, and producing different results each run would be undesirable in automation.
Which Ansible module should you use for running a simple shell command like 'date' on remote hosts?
Explanation: The 'command' module is designed to execute simple shell commands on remote hosts. 'copy' manages file transfers, 'setup' collects facts, and 'get_url' retrieves content from URLs, none of which are intended for generic shell command execution.
To install the 'htop' utility on a Linux system using Ansible, which module is most suitable?
Explanation: The 'package' module is the appropriate choice for managing software installations across various platforms. 'ping' verifies connectivity, 'service' manages services, and 'cron' schedules tasks, which are unrelated to installing packages.
Which Ansible module would you use to transfer a local configuration file to a group of remote machines?
Explanation: The 'copy' module transfers files from the control node to managed hosts. 'lineinfile' is for editing specific lines within files, 'user' creates or manages user accounts, and 'hostname' sets hostnames, but none transfer files.
If you want to make sure the 'sshd' service is running on your servers using an Ansible module, which module would you select?
Explanation: The 'service' module is used to control and ensure the desired state (running or stopped) of system services like 'sshd'. 'firewall' manages firewall rules, 'mount' deals with file systems, and 'ping' checks connectivity, none of which manage service states.
Which Ansible module is responsible for collecting details like memory, OS, and network interfaces from managed hosts?
Explanation: The 'setup' module gathers various facts about the target systems, such as hardware, OS, and network information. The 'user' module manages users, 'command' runs shell commands, and 'template' processes templates, which do not collect system facts.
To ensure a particular line is present in a configuration file, which Ansible module should be used?
Explanation: The 'lineinfile' module ensures that a specified line is present or absent within a file. 'cron' manages scheduled tasks, 'yum' installs packages, and 'shell' executes shell commands, but none focus on editing lines in files.
If you want to confirm that a remote host is reachable from the Ansible control node, which Ansible module would you use?
Explanation: The 'ping' module checks the connectivity between the control node and a target host. 'git' handles source code repositories, 'copy' transfers files, and 'file' manages file properties, all unrelated to verifying connectivity.