Ansible: a configuration management and IT automation tool

Source: Internet
Author: User

Ansible: a configuration management and IT automation tool

Today I will talk about ansible, a powerful configuration management solution compiled by Python. Although there are already many configuration management solutions available on the market, they have their own advantages and disadvantages, and ansible is characterized by its conciseness. What distinguishes ansible from the mainstream configuration management systems is that it does not require you to install your own components on each node you want to configure. At the same time, it provides an advantage that, if needed, you can control your entire infrastructure in more than one place. The last point is its correctness. It may be controversial, but I think it can still be used as an advantage in most cases. Let's start installing and configuring Ansible in RHEL/CentOS and Debian/Ubuntu-based systems.

Ansible batch build LAMP Environment

Preparations
  1. Release: RHEL/CentOS/Debian/Ubuntu Linux
  2. Jinja2: a designer-friendly Modern template language for Python
  3. PyYAML: a yaml encoding/anti-encoding function library in Python
  4. Paramiko: SSHv2 protocol function library written in Python only)
  5. Httplib2: a fully functional HTTP client function library
  6. The vast majority of operations listed in this article have been assumed that you will execute them as root users in bash or any other modern shell.
How Ansible works

The Ansible tool does not use daemon, and does not require any additional custom security architecture. Therefore, it is easy to deploy it. All you need is the SSH client and server.

  1. + ----------------- ++ --------------- +
  2. | Ansible installed | SSH | File Server 1 |
  3. | Linux/Unix workstation | <----------------> | Database Server 2 | local or remote
  4. + ----------------- + Module | Proxy Server 3 | Data Center's
  5. 192.168.1.100 + --------------- + Unix/Linux Server

Where:

  1. 192.168.1.100-install Ansible on your local workstation or server.
  2. File Server 1 to Proxy Server 3-use 192.168.1.100 and Ansible to automatically manage all servers.
  3. SSH-set an SSH key between 192.168.1.100 and a local/remote server.
Ansible installation tutorial

Ansible is easy to install. Many third-party software repositories of Release versions have ready-made software packages that can be directly installed. Other simple installation methods include installing pip or getting the latest version from github. To use your package manager for installation, you may need an EPEL repository in a RHEL/CentOS-based Linux system.

Installing ansible in RHEL/CentOS Linux

Enter the following yum command:

  1. $ Sudo yum install ansible
Install ansible In Debian/Ubuntu Linux

Enter the following apt-get command:

  1. $ Sudo apt-get install software-properties-common
  2. $ Sudo apt-add-repository ppa: ansible/ansible
  3. $ Sudo apt-get update
  4. $ Sudo apt-get install ansible
Install ansible using pip

The pip command is a tool used to install and manage Python software packages. For example, it can manage those software packages in the Python Package Index. The following method is used in Linux and Unix-like systems:

  1. $ Sudo pip install ansible
Install the latest version of ansible from the source code

Run the following command to install the latest version from github:

  1. $ Cd ~
  2. $ Git clone git: // github.com/ansible/ansible.git
  3. $ Cd./ansible
  4. $ Source./hacking/env-setup

When you run ansible from a git checkout, remember that you need to set your environment every time you use it, or you can add this setting process to Your bash rc file:

  1. # Add BASH RC
  2. $ Echo "export ANSIBLE_HOSTS = ~ /Ansible_hosts ">> ~ /. Bashrc
  3. $ Echo "source ~ /Ansible/hacking/env-setup ">> ~ /. Bashrc

The hosts file of ansible includes a series of hosts that can be operated by it. By default, ansible searches for the hosts file through the path/etc/ansible/hosts, but this behavior can also be changed, in this way, it is convenient to operate more than one ansible or for different customers in different data centers. You can use the command line parameter-I to specify the hosts file:

  1. $ Ansible all-m shell-a "hostname" -- ask-pass-I/etc/some/other/dir/ansible_hosts

However, I prefer to use an environment variable, which can be used when you want to switch the work target through a different file of source. The environment variable here is $ ANSIBLE_HOSTS, which can be set as follows:

  1. $ Export ANSIBLE_HOSTS = ~ /Ansible_hosts

Once all the required components have been installed and you have prepared your hosts file, you can try it. For quick testing, I wrote 127.0.0.1 to the hosts file of ansible:

  1. $ Echo "127.0.0.1"> ~ /Ansible_hosts

Now let's test a simple ping:

  1. $ Ansible all-m ping

Or the ssh password is prompted:

  1. $ Ansible all-m ping -- ask-pass

I have encountered several issues in the initial setup. Therefore, we strongly recommend setting SSH Public Key Authentication for ansible. However, we used -- ask-pass in the test just now. On some machines, you need to install sshpass or specify-c paramiko as follows:

  1. $ Ansible all-m ping -- ask-pass-c paramiko

You can also install sshpass, but sshpass is not always provided in the standard repository, so paramiko may be simpler.

For more details, please continue to read the highlights on the next page:

  • 1
  • 2
  • 3
  • Next Page

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.