Ansible Series Tutorial (Part 1): Introduction to Ansible and Basic Concepts

Introduction in one sentence: Ansible is an open-source automation tool that helps you manage servers in bulk, deploy applications, and execute tasks, making repetitive work automated, repeatable, and error-free.

Ansible Series Tutorial (Part 1): Introduction to Ansible and Basic Concepts

1. What is Ansible?

Ansible is an IT automation tool written in Python, used for:

·Configuration Management: Bulk modification of system configurations (e.g., adding users, installing software, etc.)

·Application Deployment: One command to deploy across all servers simultaneously

·Task Execution: Execute shell commands in bulk

·Orchestration: Define the order and conditions of task execution to achieve complex deployment processes

Unlike other automation tools (like Puppet, Chef), Ansible does not require a client to be installed on the managed nodes (Agentless); as long as you can connect via SSH, you can manage directly.

Ansible Series Tutorial (Part 1): Introduction to Ansible and Basic Concepts

2. Advantages of Ansible

1.Simple and easy to learn: Configuration files use YAML format, with clear and readable syntax, resulting in low learning costs.

2.No client agent: No need to install additional software on managed nodes, reducing maintenance costs.

3.Cross-platform: Supports Linux, Unix, macOS, Windows (requires WinRM support), and even network devices.

4.Rich modules: Thousands of built-in modules covering scenarios like software installation, file management, user management, and network device management.

5.Extensible: If the built-in modules are insufficient, you can write custom modules in Python.

Ansible Series Tutorial (Part 1): Introduction to Ansible and Basic Concepts

3. Core Concepts

Concept

Explanation

Control Node

The machine running Ansible commands, usually your management machine

Managed Node

The server being managed

Inventory

Defines the list of hosts to be managed, which can be grouped

Module

The smallest functional unit executed by Ansible, such as yum to install software, copy to copy files

Task

A specific invocation of a module

Playbook

A script composed of multiple tasks, written in YAML

Role

A way to organize Playbooks for easier reuse and division of labor

Ansible Series Tutorial (Part 1): Introduction to Ansible and Basic Concepts

4. Installing Ansible

Ansible runs on the Control Node, and the Managed Node only needs to have SSH open.

1. Install on CentOS / RHEL

sudo yum install epel-release -ysudo yum install ansible -y

2. Install on Ubuntu / Debian

sudo apt updatesudo apt install ansible -y

3. Install using pip (cross-platform)

pip install ansible

After installation, verify the version:

ansible–version

Ansible Series Tutorial (Part 1): Introduction to Ansible and Basic Concepts

5. Configuring the Inventory

The default Inventory file path:

/etc/ansible/hosts

Example:

[webservers]192.168.1.101192.168.1.102[dbservers]192.168.1.103

Ansible Series Tutorial (Part 1): Introduction to Ansible and Basic Concepts

6. Testing the Connection

Ensure that the Control Node can SSH login to the Managed Node without a password (it is recommended to use ssh-keygen + ssh-copy-id to configure public key login), then execute:

ansible all -m ping

If it returns pong, the connection is normal.

Ansible Series Tutorial (Part 1): Introduction to Ansible and Basic Concepts

7. Your First Ansible Command

For example, to check the uptime of servers in bulk:

ansible webservers -m shell -a“uptime”

·webservers: Target host group

·-m shell: Use the shell module

·-a: Module parameters

Ansible Series Tutorial (Part 1): Introduction to Ansible and Basic Concepts

8. Summary and Next Article Preview

In this article, we completed:

·Understanding Ansible’s functions and advantages

·Mastering core concepts

·Installing and configuring Ansible

·Testing and executing the first command

In the next article “Ad-hoc Commands and Common Modules”, we will learn how to execute tasks in bulk from the command line and familiarize ourselves with the usage of common modules to greatly enhance your server management efficiency.

Ansible Series Tutorial (Part 1): Introduction to Ansible and Basic Concepts

💡 Tip: It is recommended to practice with simple commands like ansible all -m ping and ansible all -m shell -a “command” before learning Playbooks.

Ansible Series Tutorial (Part 1): Introduction to Ansible and Basic Concepts

Leave a Comment