Hikerguy
Hikerguy

Reputation: 114

Ansible playbook - what is a play?

I've just started learning Ansible and have a question about what defines a "play". If I'm looking at a temple, my understanding is a play typically starts with the following:

-
  name: xxx
  hosts: yyy

I've read that the name: keyword is not required (but highly recommend). So with that being the case, how can I tell where one play begins and where the next one starts? What keywords delimit/demarc a single play when there are multiple plays in a playbook?

Thanks,

Andy

Upvotes: 6

Views: 4364

Answers (2)

Hikerguy
Hikerguy

Reputation: 114

Thanks for that link franklinsjo. That cleared things up. In summary, here's the takeaway:

A play consists of:

- name: (optional, but recommended)
  hosts:
  tasks:

So, as you're looking through a playbook, anytime you come to the keywords hosts: and tasks:, that indicates the start of a play (along with the optional name: keyword).

Thanks,

Andy

Upvotes: 2

franklinsijo
franklinsijo

Reputation: 18290

Plays:

A playbook is a list of plays. A play is minimally a mapping between a set of hosts selected by a host specifier (usually chosen by groups but sometimes by hostname globs) and the tasks which run on those hosts to define the role that those systems will perform. There can be one or many plays in a playbook.

Play refers to the set (one or more) of actions (tasks) you want to execute on a set (one of more) of hosts.

As for the syntax of a Play, you can find examples for single and multiple play playbook here.

Upvotes: 10

Related Questions