Why Ansible
Ansible automates server configuration, application deployment, and orchestration — all agentless, over SSH. Write playbooks in YAML, run them against any server.
Install
pip install ansible
Inventory
# inventory.ini
[web]
web1.example.com
web2.example.com
[db]
db1.example.com
[all:vars]
ansible_user=deploy
ansible_python_interpreter=/usr/bin/python3
First Playbook
# deploy.yaml
- hosts: web
become: true
tasks:
- name: Install Nginx
apt:
name: nginx
state: present
update_cache: true
- name: Copy config
template:
src: nginx.conf.j2
dest: /etc/nginx/nginx.conf
notify: Restart Nginx
- name: Ensure Nginx is running
service:
name: nginx
state: started
enabled: true
handlers:
- name: Restart Nginx
service:
name: nginx
state: restarted
ansible-playbook -i inventory.ini deploy.yaml
Roles (Reusable Components)
ansible-galaxy init roles/webserver
# roles/webserver/tasks/main.yaml
- name: Install packages
apt:
name: "{{ item }}"
state: present
loop:
- nginx
- certbot
- name: Deploy site
copy:
src: index.html
dest: /var/www/html/
Ansible Vault (Secrets)
# Encrypt secrets
ansible-vault create secrets.yaml
# Use encrypted vars in playbook
ansible-playbook deploy.yaml --ask-vault-pass
Key Features
- Agentless — SSH only, no agents to install
- YAML playbooks — readable, version-controllable
- Idempotent — run multiple times safely
- 3,000+ modules — cloud, network, containers, everything
- Roles — reusable, shareable from Ansible Galaxy
- Vault — encrypted secrets management
Resources
Need to extract server configs, infrastructure data, or automation metrics? Check out my Apify tools or email spinov001@gmail.com for custom solutions.
Top comments (0)