Operations 18 min read

An Introduction to Ansible: Installation, Basic Usage, and MySQL Replication with Playbooks

This article provides a comprehensive guide to Ansible, covering its purpose, installation via pip, ad‑hoc command usage, MySQL replication with the mysql_replication module, role‑based playbook structure, sample YAML files, execution output, and a comparison with other configuration‑management tools.

Art of Distributed System Architecture Design
Art of Distributed System Architecture Design
Art of Distributed System Architecture Design
An Introduction to Ansible: Installation, Basic Usage, and MySQL Replication with Playbooks

Ansible is a Python‑based configuration management and application deployment tool that operates over SSH without requiring agents on target machines.

Installation prerequisites: the control node must run Python 2.6+ (Linux/Unix), managed nodes need Python 2.4+; on RedHat/CentOS install python-setuptools , then use pip to install Ansible ( yum -y install python-setuptools , easy_install pip , pip install ansible ).

After installation you can run ad‑hoc commands, e.g., define an inventory file and execute ansible webserver -a "whoami" or ansible webserver -i /etc/ansible/other-hosts -a "whoami" . The output is JSON‑formatted.

For MySQL replication, Ansible provides the mysql_replication module. Example steps: install MySQL‑python on both master and slave ( ansible databaseServer -m yum -a "name=MySQL-python state=present" ), create a replication user on the master, enable binary logging, then use the module to get master status and configure the slave.

Playbooks allow the same tasks to be described declaratively. The article shows a role‑based directory layout (defaults, handlers, meta, tasks, templates, vars) and provides sample YAML files such as defaults/main.yml , handlers/main.yml , tasks/main.yml , and a playbook mysql_repl.yml that installs MySQL, creates users, and sets up master‑slave replication.

Running ansible-playbook mysql_repl.yml produces a sequential task list with status (ok, changed, skipped) and a final recap of successes.

A comparison table lists Puppet, Saltstack, and Ansible side‑by‑side, highlighting language, agent requirement, extensibility, encryption, platform support, UI, and configuration format.

The conclusion emphasizes Ansible’s rapid adoption, large community, and suitability for automating tasks such as MySQL replication.

automationConfiguration ManagementDevOpsMySQL replicationAnsiblePlaybooks
Art of Distributed System Architecture Design
Written by

Art of Distributed System Architecture Design

Introductions to large-scale distributed system architectures; insights and knowledge sharing on large-scale internet system architecture; front-end web architecture overviews; practical tips and experiences with PHP, JavaScript, Erlang, C/C++ and other languages in large-scale internet system development.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.