ansible Introduction to playbooks Play's structure


Here’s a simple play:

- name: Configure webserver with git
  hosts: webserver
  become: true
    package: git
    - name: install git
      apt: name={{ package }} state=present

As we said earlier, every play must contain:

  • A set of hosts to configure

  • A list of tasks to be executed on those hosts

Think of a play as the thing that connects hosts to tasks. In addition to specifying hosts and tasks, plays also support a number of optional settings. Two common ones are:

  • name: a comment that describes what the play is about. Ansible will print this out when the play starts to run
  • vars: a list of variables and values