Ansible Modules Essentials Quiz Quiz

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.

  1. Understanding Ansible Modules

    Which of the following describes the main purpose of an Ansible module?

    1. A database connection middleware
    2. A user interface for system monitoring
    3. A reusable, task-based unit of automation
    4. A platform for visual scripting

    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.

  2. Common File Module Usage

    If you want to ensure a file named 'example.txt' exists in a directory, which Ansible module should you use?

    1. user
    2. service
    3. yum
    4. file

    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.

  3. Idempotency Concept

    What does it mean when an Ansible module is idempotent?

    1. Running the same task multiple times won't change the result after the first run
    2. It requires manual confirmation to execute
    3. It only works interactively
    4. It always produces a different result on each run

    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.

  4. Using the Command Module

    Which Ansible module should you use for running a simple shell command like 'date' on remote hosts?

    1. command
    2. setup
    3. copy
    4. get_url

    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.

  5. Specifying Package Installation

    To install the 'htop' utility on a Linux system using Ansible, which module is most suitable?

    1. package
    2. cron
    3. service
    4. ping

    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.

  6. Copying Files to Remote Hosts

    Which Ansible module would you use to transfer a local configuration file to a group of remote machines?

    1. copy
    2. lineinfile
    3. user
    4. hostname

    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.

  7. Ensuring Service State

    If you want to make sure the 'sshd' service is running on your servers using an Ansible module, which module would you select?

    1. ping
    2. mount
    3. firewall
    4. service

    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.

  8. Gathering System Facts

    Which Ansible module is responsible for collecting details like memory, OS, and network interfaces from managed hosts?

    1. template
    2. user
    3. command
    4. setup

    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.

  9. Editing Lines in a File

    To ensure a particular line is present in a configuration file, which Ansible module should be used?

    1. cron
    2. shell
    3. lineinfile
    4. yum

    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.

  10. Checking Host Connectivity

    If you want to confirm that a remote host is reachable from the Ansible control node, which Ansible module would you use?

    1. file
    2. copy
    3. git
    4. ping

    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.