getting ERROR: hosts declaration is required

getting ERROR: hosts declaration is required
and i have changed lineinfile: to action: lineinfile

Looks like your indentation in your playbook is off.

Also, name should be set per task, not as a task that is just called name.