Sobes.tech
Intern

What is Ansible?

sobes.tech AI

Answer from AI

Ansible is an open-source IT automation tool used for configuration management, application deployment, and task orchestration.

Key concepts:

  • Modules: Units of code that perform specific tasks (installing packages, copying files).
  • Playbooks: YAML files describing a sequence of tasks executed on hosts.
  • Inventory: List of hosts (servers) managed by Ansible.

Example of a playbook:

---
# Playbook for installing a package on hosts

- name: Install Nginx
  hosts: webservers # Host group from inventory
  become: true # Run tasks as root (sudo)

  tasks:
    - name: Ensure Nginx is installed
      apt: # Using the apt module for Debian/Ubuntu
        name: nginx
        state: present # Ensure the package is installed
      # Example comment inside the playbook code
      # package:
      #  name: nginx
      #  state: present # Alternative for CentOS/RHEL - using package module

    - name: Start Nginx service
      service: # Using the service module
        name: nginx
        state: started # Ensure the service is running
        enabled: yes # Ensure the service starts on boot

Main advantages:

  • Agentless: Does not require installation of agents on managed hosts, uses SSH.
  • Simple syntax: Playbooks are written in YAML, making them easy to read.
  • Idempotency: Running a playbook multiple times leads to the same final state.
  • Extensibility: A large number of built-in modules and options for writing custom ones.

Applications:

  • Server configuration.
  • Application deployment.
  • Orchestration of complex workflows.
  • Automation of routine IT tasks.