Cette page est affichée en anglais. Une traduction française est en cours.
ScriptsApr 10, 2026·3 min de lecture

Ansible — Simple & Powerful IT Automation Platform

Ansible is the industry-standard IT automation tool for configuration management, application deployment, and infrastructure provisioning. Agentless, YAML-based, and SSH-powered.

Introduction

Ansible is a radically simple, open-source IT automation platform that makes applications and systems easier to deploy and maintain. Unlike tools that require agents on remote systems, Ansible uses SSH (or WinRM for Windows) to push configurations, making it agentless and easy to get started.

With 68.4K+ GitHub stars and GPL-3.0 license, Ansible is the most popular IT automation tool, used by millions of systems administrators and DevOps engineers to automate everything from code deployment to network configuration to cloud orchestration.

What Ansible Does

  • Configuration Management: Define desired system state in YAML, apply consistently across machines
  • Application Deployment: Deploy applications across multiple servers with zero downtime
  • Orchestration: Coordinate complex multi-tier deployments across environments
  • Provisioning: Provision cloud resources (AWS, Azure, GCP) and virtual machines
  • Security & Compliance: Enforce security policies and compliance standards
  • Network Automation: Configure routers, switches, and firewalls from 30+ vendors
  • Continuous Delivery: Integrate with CI/CD pipelines for automated deployment

Architecture

┌──────────────┐
│ Control Node │  (Where Ansible is installed)
│  (Your       │
│   Laptop)    │
└──────┬───────┘
       │ SSH
       │
   ┌───┴────────────────────┐
   │                        │
┌──┴───┐  ┌────┐  ┌────┐  ┌┴───┐
│ Web1 │  │Web2│  │DB1 │  │DB2 │  ← No Ansible agent needed
│      │  │    │  │    │  │    │
└──────┘  └────┘  └────┘  └────┘
   Managed Nodes (any SSH-accessible machine)

Agentless design: Only Python needs to be installed on managed nodes (and most Linux systems have it by default).

Core Concepts

Inventory

# inventory.ini
[webservers]
web1.example.com
web2.example.com ansible_user=deploy

[dbservers]
db1.example.com
db2.example.com

[production:children]
webservers
dbservers

[webservers:vars]
nginx_port=80
app_env=production

Or YAML format:

# inventory.yml
all:
  children:
    webservers:
      hosts:
        web1.example.com:
        web2.example.com:
          ansible_user: deploy
      vars:
        nginx_port: 80
    dbservers:
      hosts:
        db1.example.com:
        db2.example.com:

Playbooks

# deploy-web.yml
---
- name: Deploy web application
  hosts: webservers
  become: true

  vars:
    app_version: "2.1.0"
    app_dir: /var/www/myapp

  tasks:
    - name: Install nginx
      apt:
        name: nginx
        state: present
        update_cache: true

    - name: Clone repository
      git:
        repo: https://github.com/myorg/myapp.git
        dest: "{{ app_dir }}"
        version: "v{{ app_version }}"

    - name: Install dependencies
      npm:
        path: "{{ app_dir }}"
        state: present

    - name: Copy nginx config
      template:
        src: nginx.conf.j2
        dest: /etc/nginx/sites-available/myapp
      notify: Restart nginx

    - name: Enable site
      file:
        src: /etc/nginx/sites-available/myapp
        dest: /etc/nginx/sites-enabled/myapp
        state: link

  handlers:
    - name: Restart nginx
      service:
        name: nginx
        state: restarted

Roles (Reusable Components)

roles/
└── webserver/
    ├── tasks/main.yml
    ├── handlers/main.yml
    ├── templates/nginx.conf.j2
    ├── files/
    ├── vars/main.yml
    ├── defaults/main.yml
    └── meta/main.yml
# Using roles in a playbook
- hosts: webservers
  roles:
    - common
    - { role: webserver, nginx_port: 8080 }
    - { role: appserver, app_version: "2.0.0" }

Common Modules

# File operations
- file:
    path: /etc/myapp
    state: directory
    mode: '0755'

# Package management
- apt:          # Debian/Ubuntu
    name: nginx
    state: present

- yum:          # RHEL/CentOS
    name: httpd
    state: latest

# Service management
- service:
    name: postgresql
    state: started
    enabled: true

# Users and groups
- user:
    name: deploy
    groups: sudo
    shell: /bin/bash

# Templates
- template:
    src: config.j2
    dest: /etc/myapp/config.ini

# Command execution
- shell: |
    cd /app
    npm run build

# Cloud modules
- amazon.aws.ec2_instance:
    name: "web-{{ item }}"
    instance_type: t3.micro
    image_id: ami-12345
  loop: [1, 2, 3]

Ad-Hoc Commands

# Ping all servers
ansible all -m ping

# Check disk space
ansible all -m shell -a "df -h"

# Restart service
ansible webservers -m service -a "name=nginx state=restarted" --become

# Copy file
ansible all -m copy -a "src=/local/file dest=/remote/file"

# Install package
ansible all -m apt -a "name=htop state=present" --become

Ansible vs Alternatives

Feature Ansible Puppet Chef Salt
Open Source Yes Yes Yes Yes
Language YAML DSL (Ruby) DSL (Ruby) YAML
Agentless Yes No (agent) No (agent) Optional
Setup Very easy Moderate Moderate Moderate
Learning curve Low Medium Medium Medium
Push/Pull Push Pull Pull Both
Best for General automation Large infra Developer-centric Scale

FAQ

Q: Does Ansible require an agent on managed machines? A: No. It only needs Python (already installed on most Linux systems) and SSH access. Windows targets need WinRM configured.

Q: What infrastructure scale is it suitable for? A: Everything from a single personal server to thousands of machines. At large scale, use Ansible Tower/AWX (web UI + job scheduling) or Ansible Pull mode.

Q: How is it different from Terraform? A: Terraform is primarily for infrastructure provisioning (creating cloud resources). Ansible is primarily for configuration management (installing software and configuring machines). They often work together: Terraform creates servers, Ansible configures them.

Sources & Credits

Discussion

Connectez-vous pour rejoindre la discussion.
Aucun commentaire pour l'instant. Soyez le premier à partager votre avis.

Actifs similaires