Ansible Basic Use

Source: Internet
Author: User

Installation of Ansible


Ansible

-Based on Python Paramiko development, distributed, no client, lightweight, configuration syntax using Ymal and JINJA2 template language, stronger remote commands to perform operations.


Similar automated operations tools are commonly used in many other things:

Puppet:

-Based on Ruby development, with C/s architecture, strong extensibility, SSL-based, remote command execution is relatively weak.


Saltstack:

-Based on Python development, the C/S architecture, relatively puppet and lightweight, configuration syntax using Ymal, makes configuration scripts simpler.


Ansible working mechanism


Ansible in the Management node will Ansible module through the SSH protocol (or Kerberos, LDAP) to be executed by the management side, automatically delete after execution, you can use SVN and so on to manage the custom modules and orchestration.

650) this.width=650; "src=" Http://img0.tuicool.com/VJRfqe.png!web "alt=" Vjrfqe.png!web "/>

From the diagram above you can see that the core components of Ansible consist of 5 parts:


Ansible Core: Key;

Core Modules: including Ansible and custom modules;

Connect Plugins: Complete the module functions, including connection plug-ins, mail plugins, etc.;

Playbooks: Define Ansible Multi-task configuration file, automatically executed by Ansible;

Host Inventory: Defines the list of Ansible management hosts, host pools, host lists;


Yum Installation ansible


Yum Install Ansible (ansible relies on Python version 2.6 or higher, Paramiko, Pyyaml, and JINJA2. )


Three hosts:

192.168.38.3

192.168.38.4

192.168.38.5 (Installation ansible)


Use Ssh-keygen to generate SSH keys, transfer the secret key to two other managed hosts via ssh-copy-id-i [email protected], and test the login managed host.


Parameters of the Ansible:

-U remote Executes the command user, which defaults to root.

-I specifies the host manifest, which defaults to/etc/ansible/hosts.

-m Specifies the name of the module, which is the default command module.

The specific parameters of the-a module.

-K prompts to enter the password for the remote host.


Vim/etc/ansible/hosts The host manifest configuration file.

[Test] The test group has 2 machines.

192.168.38.4

192.168.38.3

You can also use ":" To define a series of successive hosts, which is OK to write below.

[Test]

192.168.38.[3:4]




[[email protected] ansible]# ansible-m ping ' test ' ping module testing, return Pong, on behalf of OK.

192.168.38.3 | SUCCESS = {

"Changed": false,

"Ping": "Pong"

}

192.168.38.4 | SUCCESS = {

"Changed": false,

"Ping": "Pong"

}



[[email protected] ansible]# ansible-m command-a ' uptime ' ' Test '-M command module, specifically execute uptime command.

192.168.38.4 | SUCCESS | Rc=0 >>

19:23:51 up 1:02, 2 users, load average:0.00, 0.01, 0.05


192.168.38.3 | SUCCESS | Rc=0 >>

19:23:51 up 1:02, 2 users, load average:0.00, 0.02, 0.05



[[email protected] ansible]# ansible-u root-m command-a Date ' test '-u specify user.

192.168.38.3 | SUCCESS | Rc=0 >>

Saturday, November 05, 2016 19:24:45 CST


192.168.38.4 | SUCCESS | Rc=0 >>

November 05, 2016 Sat 19:24:45 CS


Ansible group definition, 2 hosts belong to 2 groups respectively, but also belong to a large group.


Cat/etc/ansible/hosts test1 and Test2 belong to the test group.

[Test:children]

Test1

Test2


[Test1]

192.168.38.3


[Test2]

192.168.38.4




[[email protected] ansible]# ansible-a date ' test '

192.168.38.3 | SUCCESS | Rc=0 >>

Saturday, November 05, 2016 19:44:25 CST


192.168.38.4 | SUCCESS | Rc=0 >>

Saturday, November 05, 2016 19:44:25 CST


[Email protected] ansible]# ansible-a date ' test1 '

192.168.38.3 | SUCCESS | Rc=0 >>

Saturday, November 05, 2016 19:44:31 CST


[Email protected] ansible]# ansible-a date ' test2 '

192.168.38.4 | SUCCESS | Rc=0 >>

Saturday, November 05, 2016 19:44:34 CST


This article is from the "LINUX Super Dream" blog, make sure to keep this source http://215687833.blog.51cto.com/6724358/1869847

Ansible Base Use

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.