Genetic studies suggest that snakes are related to monitor lizards and iguanas, while their anatomy points to amphisbaenians ("worm lizards"), a group of burrowing lizards with snake-like bodies. A recent discovery of a tiny, 47 million-year-old fossil of a lizard called Cryptolacerta hassiaca provides the first anatomical evidence that the body shapes of snakes and limbless lizards evolved independently.
The fossil reveals that amphisbaenians are not closely related to snakes, but instead are related to lacertids, a group of limbed lizards from Europe, Africa and Asia.
A analysis using both anatomical and molecular data shows that Cryptolacerta shared a thickened, reinforced skull with worm lizards and that both were most closely related to lacertids, while snakes were related to monitor lizards like the living Komodo dragons. link
It's not closely related to ankylosaurs, either.