For all I know, the simile may come from generic Indian religious tradition and not specifically from Buddhism. For example, here are some quotes from Upanidhads:
Nirvana Upanishad (~ 100 BCE - 100 CE) :
- The phenomenal world is impermanent as it is produced [from Brahman
which alone is real]; it is similar to a world seen in a dream and an
[illusory] elephant in the sky; similarly, the cluster of things such as
the body is perceived by a network of a multitude of delusions and it is
fancied to exist as a serpent in a rope.
(Wikipedia:) The composition date or author of Nirvana Upanishad is unknown, but its sutra-style suggests that it originated in the sutra text period (final centuries of the 1st-millennium BC), before it was compiled and classified as an Upanishad. This text was likely composed in the centuries around the start of common era.
Tejobindu Upanishad (~ 100 BCE - 300 CE):
- If a man is bitten by a rope mistaken for a snake, then mundane existence may be. If a blazing fire is extinguished by a golden arrow, then the world is.
(Wikipedia:) [...] Eliade's suggestion places these in the final centuries of BCE or early centuries of the CE. [...] Gavin Flood dates the Tejobindu text, along with other Yoga Upanishads, to be probably from the 100 BCE to 300 CE period.
More of these quotes can be found in Advaita Vedanta mail list archives.
And then somewhere around 310-390 CE we see it used by the Yogacara founder Asanga in his Mahayanasamgraha:
How is this entry into Concept-Only made and what is it
like? [...] One enters in the same way that one identifies a rope which seems in the darkness to be a snake. Since it does not exist, the snake seen in the rope is an illusion. Those who have recognized that it does not exist reject the notion of snake and keep the notion of rope. But the rope itself, if reduced to its subtle elements, is an illusion itself, for it has color,
smell, taste and tactile as specific characteristics.
Thus, when any reality has been denied to the six types
of mental words which appear as phoneme or as thing - just as the notion of snake is abandoned by means of the
notion of rope - the notion of Concept-Only underlying the mental words should be abandoned by means of the notion of the absolute nature, just as the notion of rope is abandoned by means of the notion of color, etc.
Since Asanga was originally a brahmin before converting to Buddhism, I wouldn't be surprised if he took this simile from one of the Upanishads and repurposed for Yogacara.
There is also this Sanskrit version of Cittavisuddhiprakarana by Aryadeva (~200-300 CE), but I was not able to find a translation:
sarpabuddhiryathā rajjau rajjudṛṣṭau nivartate|
sarpabuddhiḥ punastatra naiva syādiha janmani||68||
sattvabuddhistathātrāpi vajrajñānānnivartate|
na bhāvaḥ sambhavettatra dagdhabīja ivāṅkuraḥ||69||
Also, this simile appears in Abhidharma Mahavibhasa Sastra which would date it around 150CE: 薩迦耶見計我我所。於勝義中無我我所。如人見繩謂是蛇。 'The satkāyadṛṣṭi thinks about the self and that which belongs to the self; but according to higher truth, there is no self. As for example, a person sees a rope and calls it a snake' (T 1545 (XXVII) 36a18-19)