Setup Ansible on a linux system
Setup Ansible with homebrew on MacOS
Ansible Setup Overview
Ansible is an open-source automation tool designed to simplify the management of IT infrastructure. It helps automate tasks such as configuration management, application deployment, and cloud provisioning across multiple servers, making it popular for DevOps tasks. The tool uses a simple, human-readable language called YAML to define tasks in “playbooks,” and communicates with remote machines over SSH.
Install Ansible
Ansible is available for most Linux distributions, macOS, and even Windows (via WSL or Cygwin). On Linux, you can install it via package managers like apt
for Ubuntu/Debian or yum
for CentOS/RHEL. On macOS, Ansible can be installed using Homebrew.
Configure SSH Access
Ansible requires SSH access to manage remote systems. You should set up passwordless SSH login between the Ansible control node and remote machines. This is typically done using SSH keys:
ssh-keygen -t rsa
ssh-copy-id user@remote_host
Create an Inventory File
Ansible uses an inventory file to define the hosts it will manage. This file can be a simple list of IPs or hostnames organized into groups.
Example inventory file (/etc/ansible/hosts
):
[webservers]
192.168.1.10
192.168.1.11
[databases]
192.168.1.20
Test Connectivity
After configuring the inventory, you can test connectivity to all the hosts using the Ansible ping
module:
ansible all -m ping
This should return a “pong” from each reachable host.
Write Playbooks
Playbooks are YAML files that define a series of tasks to be executed on remote machines. For example, a playbook can install software, update configurations, or start services.
Example of a simple playbook to install Apache:
---
- hosts: webservers
become: yes
tasks:
- name: Install Apache
apt:
name: apache2
state: present
Run Playbooks:
Once the playbook is created, it can be executed to automate tasks across the defined hosts:
ansible-playbook playbook.yml
Feel free to contact us. Find all contact information on our contact page.