templates to replace variables in template files and implement some simple logic files5 handlers and notity are used in conjunction, the action triggered by a specific condition, satisfies the condition to execute, otherwise does not execute6 tags tag specifies a task execution that selects some code in the run playbook. The ansible is idempotent, so it will aut
Preface
Two previous articles talk about ansible deployment and use of ansible modules respectively. They have an initial understanding of ansible. This article focuses on introducing playbook.For details about ansible deployment, click ansible first: DeploymentAnsible modul
Ansible playbook component, ansibleplaybook
Core elements of playbook:
Tasks: Task
Variables: Variable
Templates: Template
Handlers: Processor
Roles: Role
Organization format: YAML (also known as a Markup Language)
Syntax: (the list is represented by a horizontal bar. Key-value pairs are separated by colons, and other
There are many ways to define and reference variables in Ansible playbook, which are tested in the local environment and collated as follows. test Environment:
Using your own Mac notebook to install Ansible as the control server, the VMware Fusion virtual machine runs on a CENTOS7 virtual machine (192.168.243.146) as a
.YAML file extension is usually yml or YamlIntroduction to YAML Syntax:ListList: Lists, all of whose elements begin with "-"Example:# A List of tasty fruits–apple–orange–strawberry–mangoDictionaryDictionary: A dictionary, usually consisting of multiple keys and valueExample:—# an Employee recordName:example DeveloperJob:developerSkill:eliteYou can also place key:value in {} to represent, separating multiple key:valueExample:—# an Employee record{name:example Developer, job:developer, Skill:elite
foo /bin/foo- name : Placeholder Bar /bin/barPlaybook file used: PLAYBOOK.YMLtasks: # using include to reference the functionality of MultiplexingRoleRole: Ansible custom good standard specification, with different levels of directory hierarchy and files on the role, variables, tasks, handlers, etc. to split, for the subsequent function expansion, maintainability lay the foundation.Cases:Take the above
Ansible is a lightweight batch configuration management tool for agentless, because of the relatively late (13) development based on ansible less relevant documents, so here are some small experiments, combined with the existing data and source code, explore the Ansible two times development.The contents of the essay are divided into three parts.
Playbook-Introduction: Playbooks is a mode different from the ansible command line execution mode, and its functions are more powerful and flexible. In simple terms, playbook is a very simple configuration management and multi-host deployment system. Unlike any existing mode, it can be used as a suitable basis for deploying complex applications.
I. Description of the EnvironmentServer with Ansible installed: 192.168.13.45Test environment server: 192.168.13.49/home/app/api-tomcat/webapps/api.war a new version of the war package location for the test environmentProduction Environment server: 192.168.13.51/home/app/api-tomcat/webapps/api.war for production Environment War package location/HOME/APP/API-TOMCAT/WEBAPPS/API for production environment Project location/home/app/tomcat.bak/ api/webapps
The previous article introduced the installation configuration and example of Ansible: http://msiyuetian.blog.51cto.com/8637744/1748143The following article mainly introduces Ansible's playbook, playbook is equivalent to the module or function written into the configuration file, and then we execute the configuration file to achieve the purpose of remote operatio
I. Description of the EnvironmentServer with Ansible installed: 192.168.13.45Test environment server: 192.168.13.49/home/app/api-tomcat/webapps/api.war a new version of the war package location for the test environmentProduction Environment server: 192.168.13.51/home/app/api-tomcat/webapps/api.war for production Environment War package location/HOME/APP/API-TOMCAT/WEBAPPS/API for production environment Project location/home/app/tomcat.bak/ api/webapps
Ansible's script is written in the Yaml language, with the following basic syntax:
Basic syntax:1. Case2, the same level to be aligned, indentation representation level3, indentation is not allowed to use the TAB key4, the indentation of the number of spaces does not stipulate that the same element can be distinguished
Supported Data Structures:1. Object: A set of key-value pairs, also known as a map/hash/dictionaryExample: Name:example key: Value2, array: A set of
Meet a demand today when using Ansible-playbook after executing a script, according to the content returned by the script to determine whether to continue execution or break execution, query official website found using Register Register can be used to achieve the recording script output, using when+ Fail module to determine whether to proceed or break down, here is a simple example:
Frontier: ansible are all good, so let's talk about lookup plugins this plugin. Lookup_plugins is mainly used to implement extensions of various strings and variables within the extended playbook. For me personally, the use is not too big, but looked at the official Lookup_plugins extension list, there are some ideas. When you first use lookup, you encoun
Automated operations Tools: ansible
Application scenario for multi-process call Ansible API: Application System Check
An application system may have a cluster of 20-50 servers, and a preliminary system-level check can be checked with a unified playbook, such as (Df-h command). But deep into the application layer, there are some personalized applica
;#Ansible: TimeSync* * * * */5 */usr/sbin/ntpdate 172.16.0.1 >/dev/nullDelete Crontab[Email protected] ~]# ansible cce-m cron-a ' name= "TimeSync" state= "absent" '6. Use the Fetch module to pull the directory on the remote host to the local[Email protected] ~]# ansible cce-m fetch-a ' Src=/root/cce dest=/root/cce '7. Use the file module to manage files on the re
Perform a playbookThe above sections already have a preliminary understanding of Playbook's syntax, so how do you run a playbook?This is very simple, here's an example of running playbook in parallel, the level of parallelism is 10Ansible-playbook Playbook.yml-f 10Ansible-pull (pull configuration rather than push configuration)Can we turn the
Ansible series (5): PlaybookBefore playbook
After the first two modules, I believe that anyone who uses shell will discover the power of ansible.
Here we will introduce playbook, a truly powerful place. Let you get rid of the difficulty of executing shell.Definition of Playbook
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:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.