why use tags in an ansible playbook code example

Example 1: ansible example playbook

---
- name: update web servers
  hosts: webservers
  remote_user: root

  tasks:
  - name: ensure apache is at the latest version
    yum:
      name: httpd
      state: latest
  - name: write the apache config file
    template:
      src: /srv/httpd.j2
      dest: /etc/httpd.conf

- name: update db servers
  hosts: databases
  remote_user: root

  tasks:
  - name: ensure postgresql is at the latest version
    yum:
      name: postgresql
      state: latest
  - name: ensure that postgresql is started
    service:
      name: postgresql
      state: started

Example 2: how to use tags in ansible

# Tags goes at same indentation as name or service: 
- name: Create Postgres Container 
  tags: createcontainer
  docker_container:
    name: mypostgres
    ...
# Then in the command line:
ansible-playbook myplaybook.yaml --tags createcontainer

Tags:

Misc Example