Sobes.tech
Intern

What is Ansible?

sobes.tech AI

Answer from AI

Ansible is an open-source, easy-to-use tool for automating IT infrastructure. It is used for configuring servers, deploying applications, and orchestrating tasks.

Key features:

  • Agentless: Does not require installation of agents on managed nodes. Uses SSH (or WinRM for Windows).
  • Idempotent: Operations can be repeated multiple times without changing the final state if it is already achieved.
  • Simplicity: Uses YAML for writing playbooks, making it readable and understandable.
  • Modules: Comes with a large number of modules for performing various tasks (installing packages, copying files, managing services, etc.).
  • Extensibility: Easily create your own modules and plugins.

Main components:

  • Control Node: The server from which Ansible commands and playbooks are run. Usually Linux.
  • Managed Nodes: Servers or devices that you manage with Ansible.
  • Inventory: A file describing your managed nodes (IP addresses, hostnames, groups).
    [webservers]
    web1.example.com
    web2.example.com
    
    [databases]
    db1.example.com
    
  • Modules: Modules are actual units of code that perform specific tasks on managed nodes.
    - name: Install Nginx
      ansible.builtin.apt:
        name: nginx
        state: present
    
  • Tasks: A task is a call to a module with specific parameters. Tasks are executed sequentially.
  • Playbooks: Playbooks are YAML files containing a set of tasks to achieve a specific goal. They describe the desired state of the system.
    ---
    - name: Configure production web servers
      hosts: webservers
      become: yes  # Run tasks with sudo rights
      tasks:
        - name: Install latest version of Apache
          ansible.builtin.yum:
            name: httpd
            state: latest
        - name: Ensure Apache is running and enabled on boot
          ansible.builtin.service:
            name: httpd
            state: started
            enabled: yes
    
  • Roles: Roles gather tasks, variables, and templates into reusable structures.

Applications:

  • Configuration management.
  • Application deployment.
  • Infrastructure provisioning (e.g., configuring virtual machines after creation).
  • Task orchestration (sequential execution of actions on different nodes).
  • Automation of routine operations.