Error while executing the playbook (Structuring a YAML Playbook )

Hi, I am getting the below error message while running the playbook

[ansible@ip-10-0-1-100 ~]$ ansible-playbook mariadb.yaml
ERROR! The field 'name' is supposed to be a string type, however the incoming data structure is a <class 'ansible.parsing.yaml.objects.AnsibleSequence'>
The error appears to have been in '/home/ansible/mariadb.yaml': line 2, column 3, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
--- # Installing MariaDB
- hosts: localhost
  ^ here

My yaml file looks like below

--- # Installing MariaDB
- hosts: localhost
  remote_user: ansible
  become: yes
  become_method: sudo
  connection: ssh
  gather_facts: yes
  name:
    - name: Installing MariaDB
      yum: name=mariadb-server state=latest
      notify:
        - startservice
  handlers:
    - name: startservice
      service: name=mariadb state=restarted
Found Ansible version is 2.4.x, hence upgraded to latest version. Still same issue. Any idea where it's going wrong? Thanks in advance.

  • post-author-pic
    Pat P
    11-16-2018

    As far as I remember from top of my head, you should have line before 'name', named 'tasks:' and everything below down to handlers should be indented.

  • post-author-pic
    Pat P
    11-16-2018

    Can't edit my post:

    tasks:  
    - name: Installing MariaDB
    yum: name=mariadb-server state=latest
    notify:
    - startservice


  • post-author-pic
    Elle K
    11-19-2018

    Patryk is correct! You're using "name" instead of "tasks" as the key for that block. :)

Looking For Team Training?

Learn More