Is it possible to automatically enrol students in a group?

Yes, it is. You first have to create the groups and set an enrolment key for each of them (see how to do it at the following FAQ: Can I create groups within my course?).
Click on Users in the Course Administration menu, then on Enrolment Methods. At this point, edit the Self-Enrolment options (clicking on the “Update” icon), insert the enrolment key (please, note that the students who access the course with this enrolment key will not be included in any group; if you want students to be automatically enrolled in a group, do not communicate them this enrolment key), then select Yes in the option Use group enrolment keys. In this way, students who enter the enrolment key for group A will automatically be added in group A, and so on.

(last update: 17.07.2018)