Ansible Learning Notes 4-playbooks Task

Source: Internet
Author: User

Task List


Each play contains a task List (task list) for all hosts where a task is located

The next task executes after execution (all hosts that match the host pattern) is completed

One thing to understand is that in a play, all hosts get the same task instructions,

This is one of the purposes of play, which is to map a selected set of hosts to a task


When running playbook, if a host executes a task, the host will be from the entire playbook

Rotation, if an execution failure occurs, fix the error in playbook, and then

Re-execute can


The goal of each task is to execute a moudle, usually with a specific parameter to execute, in the argument

You can use variables


Modules is idempotent, meaning that if you execute Moudle again, only the necessary changes are performed,

It only changes where it needs to change, so it's safe to repeat the playbook multiple times.


Repeat playbook for command module and Shell module, actually repeating the same command

If you execute a command similar to chmod or Setsebool, there is no problem, and you can use the

A flag called creates. These two module become idempotent features


Each task must have a name, so that when the playbook is run, the task execution information from its output

is a good way to identify which task it belongs to, and if no value of name,action is defined, it will be used as

Marking a specific task in the output information


If you want to declare a task that previously had a format: Action:module options, it is now recommended to use

The more common format module:option


The following is a basic task definition, Service module uses key=value format parameters, which also

is the parameter format used by most module


Tasks

-Name:make sure Apache is running

SERVICE:NAME=HTTPD state=running


The more special two modudle are command and shell, they do not use parameters in Key=value format


Tasks

-Name:disable SELinux

Command:/sbin/setenforce 0

When using command module and Shell module, we need to care about the return code information, if there is a

command, which successfully executes a return code other than 0, you might want to


Tasks

-Name:run This command and ignore the result

Shell:/usr/bin/somecommand | | /bin/true

Or is that so?

Tasks

-Name:run This command and ignore the result

Shell:/usr/bin/somecommand

Ignore_errors:true

If the action line looks too long, you can separate contiguous rows with spaces or indents


You can use variables in the action row, building a variable vhost that is defined in VARs, which can be

This uses


Tasks

-Name:create a virtual host file for {{vhost}}

Template:src=somefile.j2 Dest=/etc/httpd/conf.d/{{vhost}}



This article from "Eight Miles" blog, declined reprint!

Ansible Learning Notes 4-playbooks Task

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: info-contact@alibabacloud.com 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.