I created a new Ansible playbook and got this output, i check the ansible hosts file and it’s ok.

~$ cat ansible_hosts

    [myserver]
    myserver   ansible_connection=ssh  ansible_ssh_user=root    ansible_sudo=true

Check the playbook file

~$ cat install_tools.yml

    - hosts: rancher_hosts
    
    - tasks:
      - name: "ensure packages are installed"
        apt: name=
        with_items:
          - vim
          - htop 
          - iotop
          - wget
          - curl

Try to run it and fails !!!

~$ ansible-playbook -i ansible_hosts install_tools.yml -vvvvv

ERROR! the field 'hosts' is required but was not set

Removing the dash before tasks line and correcting the identation solves the issue, i found some similar issue on reddit.

~$ cat install_tools.yml

- hosts: rancher_hosts

  tasks:
    - name: "ensure packages are installed"
      apt: name=
      with_items:
        - vim
        - htop 
        - iotop
        - wget
        - curl