Getting Started with Configuration Management and Ansible

  • What is Configuration Management?
  • How to implement Configuration Management?
  • What is Ansible?
  • How can Ansible help in Configuration Management?
  • What is Ansible Playbook?
  • How to write Ansible Playbook?
  • Configuring servers using Ansible Playbook
  • What is Ansible Galaxy?
  • Configuring servers using Ansible Galaxy
  1. Operating System Name and Version
  2. Web/Application/DB server Name and version

Why Ansible?

  • Ansible works on the push technology and does not need any special client to install on the remote server. All it needs is an SSH connection.
  • Ansible has more than 1300 modules and plugins to support web servers, database servers, networking, security, docker, Kubernetes, storage, networking, monitoring and many more.
  • Ansible has a very big community support.
  • Ansible is using YAML to get the inputs and configure remote systems
  • Ansible comes with powerful Orchestration. It can help from a VM provision to application deployment.
  • Ansible is easy to learn and adapt. It does not require any special skills to create and execute scripts

Prerequisites

Let’s get started with Ansible. Following are the base requirement.

  1. One host system for Ansible installation
  2. One server with SSH access (For this blog post requirement, there are two servers)

Additional Tips

At the time of writing, Ubuntu 18.04 may not be available on the default images of certain regions yet. To prepare two servers with Ubuntu 18.04, the custom image option can be used. To achieve this,

Installing Ansible

Step 1: Install Ansible (on the host system / Ansible system)

Ansible is not a directly available package, so you may need to install an Ansible ppa. Run the following commands:

sudo apt-get update
sudo apt-get install software-properties-common
sudo apt-add-repository ppa:ansible/ansible
sudo apt-get update
sudo apt-get install ansible

Step 2: Verify the Version (test if it works!)

ansible — version

Step 3: Update Configuration Files

There are mainly two important configuration files from the Ansible perspective:

  • ansible.cfg, as its name implies, contains all the configurations related to the ansible
  • hosts file contains a list of all the host files.

Step 4: Verifying Connection

Execute the ping command to validate if the connection is working fine:

ansible WebServer -m ping -e 'ansible_python_interpreter=/usr/bin/python3'
[WebServer:vars]
'ansible_python_interpreter=/usr/bin/python3'

Step 5: Update the Remote Server

After the successful connection test, we can apply a first basic command to update the remote server.

ansible WebServer -m apt -a "upgrade=yes update_cache=yes" -b

Step 5: Ansible Playbook

Running commands one by one does not make any difference in running a predefined shell script or the Ansible scripts. Ansible playbooks can help to resolve this issue by listing all the required steps (tasks) in one file and run them on the remote server.

Install a WebServer on ECS Server

Installing a web server involves multiple steps. To make it more convenient and easy to understand, Let’s go step by step.

---
- hosts: WebServer
tasks:
- name: Install NginX
apt: name=nginx state=latest
- name: Start NginX Service
service:
name: nginx
state: started

Deploy Default Website Page

As we installed the web server now, it is time to deploy a default website. For the scope of this blog post, we will deploy a static webpage on the server by modifying the existing playbook.

- name: "HTML Test Deploy"
become: true
syncronize:
dest: /var/www/html
src: ../default-site/

Ansible in Action

https://video-intl.alicdn.com/Blog/Ansible_in_Action.mp4

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Alibaba Cloud

Alibaba Cloud

Follow me to keep abreast with the latest technology news, industry insights, and developer trends. Alibaba Cloud website:https://www.alibabacloud.com