First, the basic introduction of Ansible:
What's the ansible type?
Ansible is a very simple IT operations automation tool engine for configuration management, application deployment, internal service orchestration, and more, for hundreds of thousands of managed nodes, based on Python development. She does not need an agent and is easy to deploy, with no other security infrastructure/configuration requirements other than SSH. She uses a very simple language (YAML) so that you can write your own automated job scripts.
How does the ansible work?
Ansible connects to the managed machine and pushes an application called "Modules" to the managed machine, Ansible then executes the modules on the managed machine (via SSH by default) and removes them when done.
Advantages of Ansible:
1, playbooks based on Yaml, easy to learn
2, based on push, no need to install any program on the managed machine
3, the controlled machine can be hundreds of thousands, the greater the scope of management cost efficiency better
4, built-in a large number of modules, and can use "any language" development of custom modules
ansibleis the new automated Operations tool, based onPythondeveloped and assembled a number of operations tools (puppet,Cfengine,Chef,func,Fabric), it realizes the functions of batch system configuration, batch program deployment, batch Run command and so on. ansibleis based on modules, and does not have the ability to deploy in bulk. The real batch deployment isansibleThe module that is running,ansiblejust provide a framework. Mainly include:
: responsible and monitored to achieve communication;
" : Specifies the host of the operation, is a host that defines the monitoring within a configuration file;
, various module core modules, module, custom module;
(5) , Playbook : When a script performs multiple tasks, it is not necessary to have the node run multiple tasks at once.
Second, how to install ansible?
In fact, the installation of ansible is not complicated, just a simple command will be done. I've tried several methods before, and I've seen several versions of the Absible installation documentation that have failed.
The following describes how to install Ansible.
Download new repo to/etc/yum.repos.d/
Epel (RHEL 7)
Wget-o/etc/yum.repos.d/epel.repo Http://mirrors.aliyun.com/repo/epel-7.repo
Add a Epel source to it.
Then go straight to yum install ansible-y !!
Third, some simple module command of ansible:
Primary server: 172.25.44.250
Prepare 3 hosts for experimental use: 172.25.44.1 172.25.44.2 172.25.44.3
Vim/etc/ansible/hosts
[Xiaoze]
172.25.44.1
172.25.44.2
[LZK]
172.25.44.3
On the primary server: Ssh-keygen generate key
[[email protected] ansible]# ssh-copy-id-i [email protected] pass the key to the other 3 experimental hosts
View Ansible supported modules: ansible-doc-l
650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M01/87/22/wKioL1fVXZbCLwF2AADw67hkDfw052.png "title=" Screenshot from 2016-09-12 05-34-59.png "alt=" Wkiol1fvxzbclwf2aadw67hkdfw052.png "/>
View a module: ansible-doc-s copy
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/87/24/wKiom1fVXenA720PAADk5KcVDhM071.png "title=" Screenshot from 2016-09-12 05-36-10.png "alt=" Wkiom1fvxena720paadk5kcvdhm071.png "/>
Ansible Command Application Basics:
Syntax: Ansible
-F Forks: Number of concurrent threads started;
-M Module_name: The module to be used;
-A args: module-specific parameters;
Basic test:
Command module:
Ansible all-m command-a ' Date '
650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M02/87/25/wKiom1fVXtyioiOvAABtQd_rNPY797.png "title=" Screenshot from 2016-09-12 05-39-41.png "alt=" Wkiom1fvxtyioiovaabtqd_rnpy797.png "/>
View passwd file:
650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M01/87/25/wKiom1fVXzfh6TC5AACmi4NeghY510.png "title=" Screenshot from 2016-09-12 05-41-54.png "alt=" Wkiom1fvxzfh6tc5aacmi4neghy510.png "/>
Cron module:
To have the managed node generate a regular automated OPS plan:
Let two hosts run every 10 minutes echo Hello World
650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/87/25/wKiom1fVYCLAv28QAAB69WdtWNY579.png "title=" Screenshot from 2016-09-12 05-45-43.png "alt=" Wkiom1fvyclav28qaab69wdtwny579.png "/>
Ansible xiaoze-a ' crontab-l ' by command to see if a task is generated
Removal task: ansible xiaoze-m cron-a ' minute= "*/10" job= "/bin/echo Hello World" name= "Test cron Job" state=absent "
Create User: Add state=absent after user delete users
650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M02/87/22/wKioL1fVYfjA4_T_AADMR3bZVkw761.png "title=" Screenshot from 2016-09-12 05-52-47.png "alt=" Wkiol1fvyfja4_t_aadmr3bzvkw761.png "/>
Delete User: Ansible all-m user-a ' name= "user1" State=absent '
Groups Management: Group
To create a MySQL group account:
650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M00/87/22/wKioL1fVYrvAK9o4AACPA0QIkrs749.png "title=" Screenshot from 2016-09-12 05-56-15.png "alt=" Wkiol1fvyrvak9o4aacpa0qikrs749.png "/>
Create a MySQL user and add it to the MySQL group:
650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M02/87/22/wKioL1fVY0GSEcaPAADsxnb3TYs501.png "title=" Screenshot from 2016-09-12 05-58-39.png "alt=" Wkiol1fvy0gsecapaadsxnb3tys501.png "/>
Copy
src=: Define local source file path
dest=: Define remote destination file path
Content=: Replaces src=, which is used to generate the target file directly with the information specified here
Copy the/etc/passwd file to the/mnt/:
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M01/87/22/wKioL1fVY9OyjiM0AAD1LwCUTTY193.png "title=" Screenshot from 2016-09-12 06-01-09.png "alt=" Wkiol1fvy9oyjim0aad1lwcutty193.png "/>
Content directly generates file contents:
650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M00/87/25/wKiom1fVZEji_SFxAAD4dwuujWo758.png "title=" Screenshot from 2016-09-12 06-03-34.png "alt=" Wkiom1fvzeji_sfxaad4dwuujwo758.png "/>
File
Change the owner of the copied file to MySQL:
650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M02/87/25/wKiom1fVZUuTF-lPAADidYFTPqY733.png "title=" Screenshot from 2016-09-12 06-07-52.png "alt=" Wkiom1fvzuutf-lpaadidyftpqy733.png "/>
Ping module:
650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M01/87/25/wKiom1fVZYOwt2knAABpkbz6f8w117.png "title=" Screenshot from 2016-09-12 06-08-52.png "alt=" Wkiom1fvzyowt2knaabpkbz6f8w117.png "/>
Service
Managing node services and startup status
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M02/87/23/wKioL1fVZirTqizfAAB60981DjY299.png "title=" Screenshot from 2016-09-12 06-11-35.png "alt=" Wkiol1fvzirtqizfaab60981djy299.png "/>
If the service is not turned on, execute the following command to open it:
650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M02/87/23/wKioL1fVaBvhlKtOAABrwLkspW4788.png "title=" Screenshot from 2016-09-12 06-19-14.png "alt=" Wkiol1fvabvhlktoaabrwlkspw4788.png "/>
Shell
Shell is recommended for piping complex command functions
650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/87/25/wKiom1fVZrKzWjahAAClIpuqhvI275.png "title=" Screenshot from 2016-09-12 06-13-53.png "alt=" Wkiom1fvzrkzwjahaaclipuqhvi275.png "/>
Yum
Install the package, uninstall the words in the back plus state=absent
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M02/87/25/wKiom1fVZ1XzJtNwAAH5h1q3so0524.png "title=" Screenshot from 2016-09-12 06-16-24.png "alt=" Wkiom1fvz1xzjtnwaah5h1q3so0524.png "/>
Uninstall is: ansible all-m yum-a "Name=bind state=absent"
This article is from the "11721816" blog, please be sure to keep this source http://zzkkk.blog.51cto.com/11721816/1851780
Ansible Study Notes