How to use Ansible for Linux configuration management
· Category: Linux
Short answer
Ansible automates configuration management using YAML playbooks and agentless SSH connections.
Steps
- Install Ansible:
sudo apt install ansible
- Create an inventory file:
[webservers]
web1.example.com
web2.example.com
- Write a playbook (
site.yml):
- hosts: webservers
tasks:
- name: Install nginx
apt:
name: nginx
state: present
- Run it:
ansible-playbook -i inventory site.yml
Tips
- Use roles to organize reusable playbook content.
- Vault encrypts sensitive variables.
- Idempotency means running a playbook twice should not change anything.
Common issues
- SSH key or password authentication must be configured beforehand.
- Python must be installed on target hosts.