Ansible Introduction:
Ansible is just a framework, does not have the ability to deploy, really has the bulk deployment ability is the ansible template,
The architecture includes:
The connection plug-in connection plugins is responsible for communicating with the monitored side.
Host Inventory: Hosts that specify operations, which are the hosts that define the monitoring within a configuration file
Various module Core Module command Module custom module
Use the plugin 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
Some elements in the ansible:
ANSIBLE.CFG: Configuration file
Inventory: library files, defining information about hosts, or host lists, manifest files
Adhoc: Simple Task
Playbook: script, Task orchestration
Task: Tasks
Handlers is called after Handlers:task execution is completed and notify is made (the action performed when the change occurs)
Roles: Role
Facts: factor, obtaining remote host information (Setup)
Notify: When the target host changes, the task execution completes and triggers notify
Ansible Common templates:
Command: Execute Linux command
Shell: Execute shell command
Copy: CP on local object to other host
Ping:ping other hosts are alive
File: Create, delete files, directories
Yum: Installing software
Service: Services Command
Ansible Common commands:
Ansible: Perform some simple and timely tasks
Ansible-playbook: Execute the scripted script
Ansible-doc: View the specific usage of a command.
Perform a part of a playbook
Ansible-playbook-i hosts Site.yml--tags config
Executive Playbook
Ansible-playbook-i hosts Site.yml
To view the specific use of a command:
Ansible-doc Yum
Use of roles:
Create the necessary directories:
MKDIR-PV Roles/zabbix/{tasks,handlers,files,vars,templates,meta,default}
Zabbix is a role name
Task: Contains a main.yml file with commands to execute
Handlers: also contains a main.yml, which is typically a command to restart the server, such as a change in the configuration file to trigger the command inside the handler
Files: A file that requires CP to a remote host
TEMPLATES:CP to the remote host template file, you can use the variable
[Email protected] ansible]# more ROLES/ZABBIX/TASKS/MAIN.YML
-name:create Zabbix config dir
File:path=/etc/zabbix/conf.d/scripts/state=directory Owner=zabbix
-Name:install Zabbix-agentd
Yum:name=zabbix22-agent State=latest
[Email protected] ansible]# more ROLES/ZABBIX/HANDLERS/MAIN.YML
-Name:restart ZABBIX-AGENTD Server
Service:name=zabbix-agentd state=restarted
The complete directory structure is as follows:
[Email protected]er ansible]# Tree
.
├──group_vars
│└──all
├──hosts
├──roles
│└──zabbix
│├──default
│├──files
││├──check_disk_io.sh
││├──check_mysql_status.sh
││├──disk_discovery.sh
││├──userparameter_mysql.conf
││└──userparameter_system.conf
│├──handlers
││└──main.yml
│├──meta
│├──tasks
││└──main.yml
│├──templates
││├──check_mysql_replication.sh
││├──get_mysql_status.sh
││├──get_mysql_variables.sh
││├──get_thread_status.sh
││└──zabbix_agentd.conf
│└──vars
└──site.yml
Catalogue Description:
Group_vars: Variable directory, all file contains the value of a partial variable, there is one between the variable and the variable value: Plus space
[Email protected] ansible]# more Group_vars/all
Dbuser: ' Monitoruser '
DBPWD: ' [email protected][email protected]#] (&) '
These variables are used in the template file.
Hosts: List of hosts, i.e. inventory library files
[[email protected] ansible]# more hosts
[Test]
10.24.16.140
10.46.77.24
Roles: Role Directory
Zabbix: List of roles
SITE.YML: Arranging roles, task portals
[Email protected] ansible]# more SITE.YML
-Name:instal Zabbix Agent
Hosts:test
Roles
-Zabbix
Learning Links:
Ansible Common templates
http://blog.csdn.net/iloveyin/article/details/46982023
Ansible Chinese Manual
http://www.ansible.com.cn/
Ansible Study notes-general operations
http://www.axiaoxin.com/article/167/
How to use roles:
Http://www.tuicool.com/articles/AZVJ3qQ
This article is from the "SQL Server MySQL" blog, so be sure to keep this source http://dwchaoyue.blog.51cto.com/2826417/1826339
A brief introduction to Ansible