Ansible ابزار Configuration Management و Automation از Red Hat هست. Agentless، ساده، قدرتمند.

مزایا

Agentless: نیاز به نصب چیز روی سرور
SSH: از SSH استفاده میکنه
YAML: خوانا
Idempotent: چند بار اجرا، نتیجه یکسان

نصب

pip install ansible
یا: apt install ansible

Inventory

inventory.ini:
[webservers]
web1.example.com
web2.example.com
[databases]
db1.example.com

Playbook

playbook.yml:
- hosts: webservers
  tasks:
    - name: Install nginx
      apt: name=nginx state=present

Run

ansible-playbook -i inventory.ini playbook.yml

Ad-hoc Commands

ansible webservers -m ping
ansible all -a "uptime"

Modules

apt/yum: package
file: file
copy: کپی
template: Jinja2
service: خدمات
user: کاربر

Variables

vars:
  app_port: 3000

Handlers

اگه چیزی تغییر کرد:
notify: restart nginx
handlers:
  - name: restart nginx
    service: name=nginx state=restarted

Roles

ساختار پروژه برای reusability.

Ansible Galaxy

Repository رایگان از Role های آماده.

Vault

ansible-vault encrypt
Password ها رو رمزنگاری کنید.

Tower/AWX

Web UI برای Ansible.

Best Practices

Idempotent: مواظب باشید
Test: با Docker یا Vagrant
Documentation: کامنت

سباهاست

مدیریت VPS و Dedicated سباهاست با Ansible.

جمع‌بندی

Ansible مهارت مفید برای مدیریت سرور در مقیاس.