Ansible Quick Start

Source: Internet
Author: User
Tags saltstack

Recently, I am entangled in how to choose from Puppet, Chef, SaltStack, Ansible, and other configuration management tools. Considering that the changes are a lot of troubles once they are not selected at the beginning, it is a little cautious.

I have used Puppet and SaltStack, but it is not exactly as expected, so we should first exclude it. As for Chef, although I have heard of it for a long time, I have never found a chance to try it. After reading the document, Chef uses the server/client mode like Puppet and SaltStack. It is still difficult to deploy a certain number of machines. Finally, the ticket is placed on Ansible. After playing with Ansible, I feel like Ansible is quite similar to me. I like Ansible in the following aspects:

  • Make full use of existing facilities. You do not need to install the server and client to use Ansible. You only need to use SSH. This means that any machine with Ansible can become a powerful management end. I think this decentralized approach is more flexible. Some may worry about SSH efficiency. Ansible's parallel execution and acceleration mode may eliminate your concerns.
  • Easy to use and quick to get started. I didn't spend much time researching Puppet before I used it. Think about it. Aren't we just trying to free ourselves from repetitive and complex tasks? Isn't it cost-effective to sink into another complicated thing to simplify one thing? In my experience, Ansible is very quick to get started. Ad-Hoc can be used to handle simple management tasks. You can also define the Playbook file to solve the problem.
  • Adopts the human readable format. The host definition file of Ansible uses the INI format, supports grouping and can specify the mode. In addition, it can also be dynamically generated, which should be useful for managing VM instances. Playbook is in YAML format. I think it is easier to read and write than Puppet DSL.
  • You can use a language you are familiar with to compile modules. Although Ansible is developed using Python, it does not limit you to a specific programming language, Bash, Python, Perl, Ruby, and so on. You can use whatever you are good.

In a word, the philosophy behind Ansible is deeply rooted in me. This is also in line with the principle of Choosing Software.

Some people may be concerned about who is using Ansible. After all, the power of role models is infinite. Puppet is not correct because Google is in use and attracts a lot of attention? As far as I know, the well-known Ansible users include Fedora, Rackspace, and Evernote.

Install Ansible

Ansible can be installed on Linux, BSD, Mac OS X, and other platforms. The minimum Python version requirement is 2.6. For common Linux distributions, you can install Ansible through its own Package Manager:

Yum install ansible # RHEL/CentOS/Fedora, You need to configure EPELapt-get install ansible # Debian/Ubuntuemerge-avt ansible # Gentoo/Funtoo

If you cannot find Ansible in the package repository of the Linux release, you can also usepipInstall Ansible, and install Python dependent libraries such as paramiko, PyYAML, and jinja2.

pip install ansible

Prepare Inventory

The Inventory file is used to define the host you want to manage. The default location is/etc/ansible/hostsIf it is not saved in the default location, you can also use-iOption.

The managed machine can be specified through its IP address or domain name. Ungrouped machines must be retained at the top of hosts.[]Such:

[web]linuxtoy.org

Groups can also be nested:

[vps:children]webdb

In addition, you can specify a series of consecutive hosts by using numbers and letters, such:

[] .Linuxtoy.org # is equivalent to 1.linuxtoy.org, 2.linuxtoy.org, and 3.linuxtoy.org [a: c] .linuxtoy.org #. It is equivalent to a.linuxtoy.org, B .linuxtoy.org, c.linuxtoy.org

Test Tool

Now, run the following command to check whether Ansible works properly:

ansible -i hosts all -m ping -u www

The options of this command are used as follows:

  • -i: Specifies the inventory file, using the hosts in the current directory
  • all: Run on all hosts defined by hosts. You can also specify the group name or mode.
  • -m: Specify the modules used. We use the Ansible built-in ping module to check whether remote machines can be managed normally.
  • -u: User of the remote machine

If the following result is returned:

linuxtoy.org | success >> {    "changed": false,    "ping": "pong"}

It means everything is normal.

Next let's look at the uptime of the remote machine:

ansible vps -a 'uptime'

This will output:

linuxtoy.org | success | rc=0 >>11:23:16 up 177 days, 21:19,  0 users,  load average: 0.55, 0.45, 0.39

Here we omit-m, Ansible uses the command module by default;-aSpecify the module parameters, that is, executeuptimeCommand.

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

For more information about Puppet, click here.
Puppet: click here

Research on three Backup Recovery solutions for Puppet agent

Register your Puppet node in a safer way

Deep understanding of Puppet syntax and working mechanism through SSH Configuration

Puppet uses Nginx multiple ports for Load Balancing

C/S mode instance of Puppet in CentOS (5 and 6)

  • 1
  • 2
  • Next Page

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.