Getting started with a brief introduction to Ansible

Source: Internet
Author: User

AnsibleSimple Description

Ansible is a new automated OPS tool that is developed based on Python and has a large collection of operations tools (puppet,cfengine,chef, Func,fabric), 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, andansible just provides a framework. Mainly include:

(1) , connection plug-in connectionplugins: Responsible for and be monitored to achieve communication;

(2) ,host inventory: Specifies the operation of the hosts, is a configuration file inside the definition of monitoring host;

(3) , various modules core module,command module, custom module;

(4) , with the help of plug-ins to complete log mail and other functions;

(5) ,playbook: When a script performs multiple tasks, it is not necessary to have the node run multiple tasks at once.

Ansiblethe installation configuration
    1. Configuring the Yum source, direct Yum installs the

    2. Configure your own Epel source https://mirrors.tuna.tsinghua.edu.cn/help/epel/ Tsinghua students to maintain the

    3. Http://mirrors.aliyun.com/help/epel Ali's

# yuminstall ansible–y installation

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M01/8B/A5/wKiom1hTeAHREZ7RAAS17GoxGS8462.png "title=" 1.png " alt= "Wkiom1hteahrez7raas17goxgs8462.png"/>


650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/8B/A5/wKiom1hTeCOjpyHNAAJC6Hq5b28136.png "title=" 2.png " alt= "Wkiom1htecojpyhnaajc6hq5b28136.png"/>

Enter ANSIBLE-V to see the version information, indicating that we have successfully installed


650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M01/8B/A1/wKioL1hTeHDQVmlqAAKQfsfhHdM658.png "title=" 3.png " alt= "Wkiol1htehdqvmlqaakqfsfhhdm658.png"/>

650) this.width=650; "Src=" Http://s3.51cto.com/wyfs02/M02/8B/A5/wKiom1hTeHzxTrt1AABvxBJv08A979.png-wh_500x0-wm_3 -wmp_4-s_3132731496.png "title=" 4.png "alt=" Wkiom1htehzxtrt1aabvxbjv08a979.png-wh_50 "/>

write our first order.

Inventory This is the machine that needs to be managed to follow this one is write, also say the Hosts inside .

First , add one of our tests to this hosts file and play it:

Can be directly used domain name and IP to represent: # # green.example.com## blue.example.com## 192.168.100.1## 192.168.100.10 can define groups: # # # [webservers]## alpha.example.org## beta.example.org## 192.168.1.100## 192.168.1.110 can define a section of the domain name of the rule: # # www[001:006].example.com## [ dbservers]## # db01.intranet.mydomain.net## db02.intranet.mydomain.net## 10.25.1.56## 10.25.1.57## db-[99:101]- Node.example.com

I added one of my server addresses at the end:


# # [Dbservers]

##

# # Db01.intranet.mydomain.net

# # Db02.intranet.mydomain.net

# # 10.25.1.56

# # 10.25.1.57


# Here's another example of host ranges, this time there is no

# leading 0s:


# # Db-[99:101]-node.example.com

192.168.61.129 #这是我加入的

Next, let's run our first command:

Ansible ' 192.168.61.129 '-M ping–k

The wrong public key,

-U: Specifies the user name at the time of connection, the default is root, so it is possible not to add this option

-K: Prompt for password, abbreviated form of--ask-pass

Either modify the Ask_pass = True of the ansible.cfg configuration file to uncomment it, or add-K when you run the command, meaning-K,--ask-pass ask for SSH password. Re-modify: host_key_checking= false, I am direct ssh 192.168.61.129 landed once, and then the execution was OK.


[Email protected] ansible]# ansible ' 192.168.61.129 '-M ping-k

SSH Password:

192.168.61.129 | failed! = = {

"Failed": true,

"MSG": "Using a SSH password instead of a key is not possible because Host keychecking are enabled and Sshpass does not supp  Ort this. Please add this host's fingerprint to yourknown_hosts file to manage this host. "


650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M02/8B/A1/wKioL1hTe3vRJ5zVAAJbzwLEKK0806.png "title=" 5.png " alt= "Wkiol1hte3vrj5zvaajbzwlekk0806.png"/>


Ansible ' 192.168.61.129 '-M shell-a ' date ' –k one more command


650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M01/8B/A1/wKioL1hTe8iBNDK6AABhDDVdgsg421.png "title=" 6.png " alt= "Wkiol1hte8ibndk6aabhddvdgsg421.png"/>

a little experimentsend the public key to other machines for password-free login

First this Ansible Machine generated key pair : Ssh-keygen-t rsa-b 2048 All-way return

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/8B/A5/wKiom1hTe_LAMi9-AAFnhQRxHpM509.png "title=" 7.png " alt= "Wkiom1hte_lami9-aafnhqrxhpm509.png"/>

Collect the public key of the logged-on host first

Ssh–keyscan Command

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/8B/A1/wKioL1hTfB7AhMhEAACsF8NQ4qY316.png "title=" 8.png " alt= "Wkiol1htfb7ahmheaacsf8nq4qy316.png"/>

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M00/8B/A5/wKiom1hTfDqBN7kfAABz4O61tas276.png "title=" 9.png " alt= "Wkiom1htfdqbn7kfaabz4o61tas276.png"/>

So the collection is complete.


Below the parameters of their own Baidu to view:

the module used is Anthorized_key

in the current directory, a new ssh-addkey.yml file is created and the command used:Ansible-playbook

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M00/8B/A5/wKiom1hTfG3iCWklAAEV7IdJhk0136.png "title=" 10.png "alt=" Wkiom1htfg3icwklaaev7idjhk0136.png "/>


Ansible-playbook ssh-addkey.yml–k Execute this command bulk push

error, need to run Setenforce on the remote host 0

Ansible all-m yum-a ' name=libselinux-pythonstate=present ' –k also to install this package

Run it again Ok

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M00/8B/A1/wKioL1hTfJmhGGvWAAFtuUbs8kg826.png "title=" 11.png "alt=" Wkiol1htfjmhggvwaaftuubs8kg826.png "/>

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M01/8B/A5/wKiom1hTfLyxtSeuAAJ7w16CzPE528.png "title=" 12.png "alt=" Wkiom1htflyxtseuaaj7w16czpe528.png "/>

This remote shuts down the SELinux

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/8B/A1/wKioL1hTfO3S62wfAAEl5UzJTRs005.png "title=" 13.png "alt=" Wkiol1htfo3s62wfaael5uzjtrs005.png "/>

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M01/8B/A1/wKioL1hTfRjwO-9hAADgZW26w-s229.png "title=" 14.png "alt=" Wkiol1htfrjwo-9haadgzw26w-s229.png "/>

Final execution Command Ansible-playbook ssh-addkey.yml-k

Then do not have to add the K option, directly without the password with key to login execution:

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M02/8B/A1/wKioL1hTfbygvBbKAABIkZ89Hcg814.png "title=" 15.png "alt=" Wkiol1htfbygvbbkaabikz89hcg814.png "/>


In fact, you can also use the ansible copy module can also be reached to the public key to other host designated directory, left to test it:

Ansible all-m copy-a ' src=/etc/ansible/ssh-addkey.yml dest=/tmp/ssh_addkey.yml '

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M00/8B/A1/wKioL1hTfeOjwZ5UAAEnOB7KpiY324.png "style=" float: none; "title=" 16.png "alt=" Wkiol1htfeojwz5uaaenob7kpiy324.png "/>

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M00/8B/A1/wKioL1hTfeSSSSFtAAE1D0Z9ZkA323.png "style=" float: none; "title=" 17.png "alt=" Wkiol1htfessssftaae1d0z9zka323.png "/>

Come here today, another day to talk about modules, role,task and so on.

Getting started with a brief introduction to Ansible

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.