Ansible playbook not running for localhost also, how to fix this?

You don't need ssh connection for the localhost.

Just update your hosts file to include ansible_connection=local for localhost

localhost ansible_connection=local

Also, make sure you are not overriding ansible_connection to ssh anywhere else.