Executing one task from a playbook using tags

Solution 1:

The problem is that in Ansible on is evaluated as Boolean True and off is evaluated as Boolean False. See Testing truthiness. For example

    - debug:
        msg: "{{ my_tag }} is truthy {{ my_tag is truthy }}"
      vars:
        my_tag: on

gives

  msg: True is truthy True

When you use Boolean in a tag, e.g.

    - debug:
        msg: tag on
      tags: on

Ansible complains

ERROR! tags must be specified as a list

This error is misleading. In fact, Ansible complains about the type of data. The solution is simple. Do not use Boolean as a tag, e.g. the task below works as expected

    - debug:
        msg: tag my_on
      tags: my_on

gives

shell> ansible-playbook playbook.yml --tags my_on
...
  msg: tag my_on

You can use a list in tags. But, if you put a string into the tags it will be interpreted as a single item of a list. See Tags.