OPS tool Ansible Quick Start tutorial

Source: Internet
Author: User
Tags ssh aliyun
Ansible Introduction

Ansible is a new automated operation tools, based on Python development, the collection of a number of operations tools (puppet, Cfengine, Chef, func, fabric) The advantages of the implementation of batch system configuration, batch program deployment, batch Run command and other functions.

Ansible is a module-based operation and does not have the capacity to deploy in bulk. The real batch deployment is the module that Ansible runs, and Ansible just provides a framework. Mainly include: (1) connection plug-in connection plugins: responsible for and be monitored to achieve communication; (2) Host inventory: The host that specifies the operation, is the host that defines the monitoring in a configuration file, (3) Various module core module, command module, Custom modules, (4) The use of plug-ins to complete logging mail and other functions; (5) Playbook: When a script performs multiple tasks, it is not necessary to allow the node to run multiple tasks at once. Experimental Environment

Virtual Machine x2, operating system: Tinycorelinux, created by Docker-machine. Installing Ansible

Tinycorelinux mirroring use help-accelerating software Installation

1. Install Python, python-setuptools

Tce-load-wi python Python-setuptools

2. Install Pip

sudo easy_install-i http://mirrors.aliyun.com/pypi/simple/pip

3, Installation Ansible

sudo pip install-i http://mirrors.aliyun.com/pypi/simple/--trusted-host mirrors.aliyun.com ansible

4. Verification Ansible

Ansible--version
using SSH to manage other hosts

1. Generate secret key Id_rsa and Id_rsa.pub

$ cd ~/.ssh/

$ ssh-keygen-t RSA

2. Add public key id_rsa.pub content to the ~/.ssh/authorized_keys file of other hosts

3. Add hosts in the/etc/ansible/hosts file that need to be managed

$ sudo vi/etc/ansible/hosts

[swarm]
192.168.99.103  ansible_connection=ssh  ansible_ssh_user= Docker

4. Test: Manage other hosts create Hello folder

Ansible all-a "mkdir Hello"

Prerequisites: Other hosts need to install Python, otherwise the following error will be reported

docker@managerx:/etc/ansible$ ansible all-a "/bin/echo hello"
192.168.99.101 | failed! = = {
   "changed": false,
   "Module_stderr": "Shared connection to 192.168.99.101 closed.\r\n",
   "Module_ StdOut ":"/bin/sh:/usr/bin/python:not found\r\n ",
   " msg ":" MODULE FAILURE ",
   " RC ": 0
}

Tinycorelinux installed Python execution commands under the/usr/local/bin/python path, so to soft connect to/usr/bin/python, the command is as follows:

sudo ln-s/usr/local/bin/python/usr/bin/python

There is also a way to specify the Python path, edit the/etc/ansible/hosts

[Swarm]
192.168.99.103  ansible_connection=ssh  ansible_ssh_user=docker ansible_python_interpreter=/usr/local/bin /python

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.