Can I use group name in /etc/ansible/hosts as a variable in templates or playbook script?

{{ inventory_hostname }}

Thank you!

Another question:
I has one task on host group A. This task need hosts name in host group B as variable in template. Is it possible?

Absolutely!

{{ groups["groupB"] }}

in a template contains the list of all host names in group B.

You can even iterate across it to access "hostvars" to pull out the IP
addresses of all the machines in that other group, etc!

--Michael