How to use Ansible for Linux configuration management

· Category: Linux

Short answer

Ansible automates configuration management using YAML playbooks and agentless SSH connections.

Steps

  1. Install Ansible:
sudo apt install ansible
  1. Create an inventory file:
[webservers]
web1.example.com
web2.example.com
  1. Write a playbook (site.yml):
- hosts: webservers
  tasks:
    - name: Install nginx
      apt:
        name: nginx
        state: present
  1. 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.