Ansible study record five: Playbook study

Source: Internet
Author: User
Tags ansible playbook ansible roles

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://

Playbooks is the use of Ymal language structure, basic syntax please refer to:

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

├── Batch installation shell.

└── 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:





-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 ' ( ' 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)?


Vim/etc/ansible/ansible.cfg or ~/.ansible.cfg


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


The playbook configuration of cluster operation and maintenance ansible and the use of template templates


Playbook Roles and Include statements


Ansible study record five: Playbook study

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: 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.