0. Introduction
Playbooks is the language of Ansible management configuration, deployment applications, and orchestration, and you can use playbooks to describe the policies you want to perform on the remote host or the set of steps that you perform.
Similar to a set of task sets, defining information such as projects, organizational structures, profiles, and so on, the task is to organize the things you want to do in one step and the whole playbook
Official Demo information: Https://github.com/ansible/ansible-examples
Playbooks is the use of Ymal language structure, basic syntax please refer to: http://docs.ansible.com/ansible/YAMLSyntax.html
A complete playbooks structure to deploy Tomcat as an example:
tomcat/------> Tomcat Playbook
├──hosts--------> Specify a list of machines to install Tomcat (Inventory)
├──roles------> Child list (can have one or more tasks)
│└──tomcat----> Install tomcat
│├──files---> Storage files
││├──apache-tomcat-7.0.64.tar.gz----> Tomcat installation package
││├──jdk-7u79-linux-x64.tar.gz-----> JDK Installation package
││└──TOMCAT------>tomcat Service startup script
│└──tasks------> Task Item List
│├──JDK.YML---> JDK task List
│├──MAIN.YML---> Mission portal
│└──TOMCAT.YML---->TOMCAT Task List
├──SITE.YML ansible Playbook Executive Portal
├──tomcat.sh Batch installation shell.
└──tomcat-testing.sh Tomcat Installation test script
Ansible Roles Complete Example:
[Email protected] playbook]# tree roles/
roles/\\ansible All the information is placed in the directory below this directory
└──nginx \ \ Role Name
├──default \ \ Use this directory when setting default variables for the current role, should contain a main.yml file;
├──files \ \ Store files that are called by a module such as copy or script
├──handlers \ \ This directory should always contain a main.yml file that defines the handler used by each role
├──meta \ \ Should contain a main.yml that defines the special settings of the role and their dependencies; 1.3 and later version support
├──tasks \ \ Contains at least one file named Main.yml that defines a list of tasks for this role, which can be used with the include directive
├──templates \\template module will automatically look for Jinja2 template files in this directory
└──vars \ \ Should contain a main.yml file that defines the variables used by this role
1. Introduction to the project structure
The properties in Playbook are described in:
Name indicates the Playbook
Hosts represents the list of machines executed
Connection: Allows you to specify SSH Parmiko or local three modes of transmission
Gather_facts: Setup is performed for each connection by default, and if you do not need to use a variable you can make this field now
Remote_user: User executed by remote side
Tasks: Define the Task list for execution, sequential execution
Templates: Storing template files
VARs: Storing variables
Handlers: Define a method for future callbacks
File: Store the copied installation files, such as installation files, etc.
2.PlayBook Example
To install the FTP service:
---
-Hosts:test
Remote_user:root
Tasks
-Name:install FTP
Command:yum-y Install FTP
3. Other
3.1 Tips for checking keys will appear after the first connection or reload of the system
The Authenticity ofhost ' 192.168.0.5 (192.168.0.5) ' can ' t be established.
ECDSA key fingerprint is 05:51:e5:c4:d4:66:9b:af:5b:c9:ba:e9:e6:a4:2b:fe.
Is you sure want to continue connecting (yes/no)?
Workaround:
Vim/etc/ansible/ansible.cfg or ~/.ansible.cfg
[Defaults]
host_key_checking = False
You can also disable such hints by setting the system environment variable
Export Ansible_host_key_checking=false
3.2 When using Paramiko mode, the host keys check will be very slow
3.3 By default, Ansible records information such as the parameters of some modules into the Syslog log file of each controlled terminal, unless the no_log:true is not recorded in the task or script.
4. Reference Records
Ansible-playbook
http://www.178linux.com/7001
The playbook configuration of cluster operation and maintenance ansible and the use of template templates
Http://www.tuicool.com/articles/UvU3ai
http://rfyiamcool.blog.51cto.com/1030776/1413031
Playbook Roles and Include statements
Http://docs.ansible.com/ansible/playbooks_roles.html
Ansible study record five: Playbook study