Ansible Getting Started

Source: Internet
Author: User

Objective

I've been looking at ansible. A configuration management tool, compared to Big Brother Puppet, is simpler to use and can execute commands in bulk, comparing Saltstack written in Python, without having to install a client (based on Paramiko). Also more flexible, especially our existing login method, through the Springboard Machine encryption key, converted into ansible cost is very low, ready to learn about later in the production of the use.

Ansible has been acquired by Red Hat and is now 2.0, chatting with a friend of Red Hat, an OpenStack (Red Hat is one of the biggest contributors to its code) that is now a big contributor to the fire, and it seems to be a trend in automating operations.

Official Address http://docs.ansible.com/

Installation

After the simplest epel, yum install ansible

You can also use the Pip method

Pip Install ansible can

If the server can't connect to the public network like we do, you need to download the Python module manually ecdsa, Pycrypto, Paramiko, Markupsafe, JINJA2, Pyyaml, ansible

The currently installed version is 1.9.4

Ansible--1.9.4
Getting Started with

First the SSH key to do well, here does not say, to ensure that the master and minion between the password

Define hosts and Groups:

Vim/etc/ansible/hosts #默认的文件位置, can also execute ansible when manually specifying the Hosts file, through the-I parameter

[test]10.199.2.4510.199.2.46[web]10.199.2. [42:47]  # =10.199.2.42\43\44\45\46\47test.case.com  # host name definition

Use the first module:

Ansible test-m ping-u sre-s #-m module name, because we are using the SRE account login via sudo way,-u connect the user,-s indicates sudo way to execute
Ansible test:\!10.199.2.46-m ping-u sre-s #:!\ exclude a host
Ansible 10.199.2.46-m ping-u sre-s #当然也可以直接接ip而不使用组进行

Ansible comes with a lot of modules.

You can see which modules are in total by ansible-doc-l, Ansible-doc Ping shows the usage of a module, ansible-doc-s ping shows code snippets for a module in playbooks

To execute a command module remotely:

Remote execution commands are probably the most common and convenient feature of ansible, here are a few examples

1. Execute Minion Operating system commands

Ansible test-a ' W '-U sre-s #默认模块command, implementation of remote command,-a module parameters

Execute script on Master on 2.minion

Master first creates the script 1.sh

# !/bin/bash  /tmp/
' 1.sh ' -u sre-s  #script module is equivalent to Scp+shell, local script is executed at remote minion

3.minion execute Minion on script, 2.45 remote presence minion.sh,2.46 not present

Shell and command modules are similar, see Help information to understand the command and shell functions are basically consistent, but the shell can use environment variables, pipelines, etc., more powerful

Ansible Getting Started

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.