First, what kind of situation requires a lot of deployment
1, the installation of the operating system
Common is collber,red hat satelite (Redhat) system dedicated.
2, the operating system configuration
Common to have cfengine,puppet,chef,func. One of the most popular puppet
3, the deployment of batch programs
4, the volume command run View status information
Ii. introduction of Ansible
The structure of the ansible is generally as follows
Ansible is a new Operation tool is based on Python research and development of a combination of the advantages of a number of veteran operational tools to achieve the bulk of the operating system configuration, batch program deployment, batch operation commands and other functions.
Common working modes of operational tools
1, Agent mode: based on SSL implementation. The agent works on the monitored side. Like puppet.
2, agentless mode: Based on SSH service implementation work in the monitored side. The monitor end is the client of SSH.
Ansible is the power of the work in the agentless mode. Ansible at the control end only need to tell the monitoring side of the desired state can achieve bulk deployment.
noun explanation
Idempotent does not repeat the same instruction. For example, do not repeat the installation of software
The desired state only needs to tell the desired state of the monitored end
Ansible is based on the modular work of the ansible itself without the ability to bulk deploy. What really has a lot of deployments is the module that Ansible is running ansible just provides a framework. Architecture includes
The connection plug-in connection plugins is responsible for communicating with the monitored end.
Host Inventory: Specifies the operation of the master, is a configuration file that defines the monitoring of the host
Various Modules Core Module command Module custom module
The use of Plug-ins to complete log mail and other functions
Playbooks: When a script performs multiple tasks. It is not necessary to have nodes run multiple tasks at once
Iii. Basic methods of use
When managing a cluster, Ansible needs to first configure the cluster hosts list to facilitate cluster operations
The code is as follows:
$ cat/etc/ansible/hosts
[Local]
# Configure password login, need to ansible the local installation Sshpass
192.168.213.135 Ansible_ssh_user=root Ansible_ssh_pass=root
[Zabbix]
# Key Login
172.17.0.2:49154 Ansible_ssh_user=root
172.17.0.4:49155 Ansible_ssh_user=root
[VPN]
172.17.0.10
Test Connection Log OK
The code is as follows:
$ ansible local-m Ping
192.168.213.135 | Success >> {
"Changed": false,
"Ping": "Pong"
}
Ansible common usage is the Ansible host-pattern-m module-a command, host-pattern a simplified regular expression, and the module can be queried by the ansible-doc-l command. Here are some common ways to use modules:
Install the Software:
The code is as follows:
Ansible local-m apt-a ' NAME=GCC state=present '
Or
The code is as follows:
Ansible local-m yum-a "Name=nmap state=installed"
To execute a command:
The code is as follows:
Ansible local-m shell-a ' uptime '
Copy file:
The code is as follows:
Ansible local-m copy-a "Src=/tmp/server dest=/tmp/server"
File properties:
The code is as follows:
Ansible local-m file-a "Dest=/tmp/server mode=755 owner=root"
*
Playbook
Playbook is a list of one or more "play". The main function of play is to dress up as a group of hosts in advance through the task defined by the Ansible role.
A simple playbook configuration is as follows:
The code is as follows:
-Hosts:local
Remote_user:root
Tasks
-Name:echo Hi
Shell:echo "HI"
Ansible also supports setting up handlers,handlers to be invoked after the server changes after the tasks are performed, using the following handler:
The
Code is as follows:
# PLAYBOOK.YML
---
-hosts:local # hosts specify
Remote_user:root # if you are the same as the current user, you do not need to specify
tasks:
-Name:whoami
copy:src=~/hosts dest=~/hosts.dest # Local copy to remote
Notify: # If copy is done ~/ Hosts.dest file sends a change, then perform a
-clear copy # call handler
Handlers:
-name:clear copy
Shell: ' MV ~/hosts.dest Hosts.del ' # pretended to delete the