The earliest instance I have found of "play the cards [one is] dealt" as a figurative expression meaning "try to make the best of the situation that one finds oneself in" is from Charles Lever, The Martins of Cro' Martin (1856):
"But do you like his conditions?" asked Jack.
"I can't say I do. But what's that to the purpose? One must play the hand that is dealt to them—there's no choice! I know that, as agent over the property, he'll make a deuced good thing of it for himself. It will not be five nor ten per cent. will satisfy Master Maurice."
But the idea that, under certain circumstances, one has the option not to play the hand that one is dealt in an an actual game of cards appears in print much earlier. From James Beaufort, Hoyle's Games Improved: Being Practical Treatises on the Following Fashionable Games, Viz. Whist, Quadrille, Piquet, Bck-gammon, Chess, Billiards, and Tennis (1775):
In order to give a general idea if the game [Piquet], as we have proposed, it is necessary to observe here, that if the elder or younger hand has thirteen cards dealt him, it is at the option of the elder hand either to play the cards, or to have a new deal ; and if he chuses to stand the game, he is to lay out one more than he takes in, so that there may be three cards left to the dealer. If the younger hand has thirteen cards, he must in like manner lay out on more than he takes in ; and if either party has fourteen cards dealt him, there must be a new deal.
The example of the figurative expression from 1856 is interesting in that it doesn't seem to arise as a striking turn of phrase by a particularly poetical or inventive speaker (Captain Martin), but rather as a kind of axiomatic observation familiar to both the speaker and the hearer in the novel. Charles Lever was born and raised in Ireland, and his novel is set there.
In a comment beneath Stuart F's answer, Peter Shor notes the following very similar metaphorical usage, from The Hunted Heir, serialized in The Young Ladies' Journal (May 1, 1868):
"It shall be so," he [Gaspard] said—"it shall be as you will, Clemence, though the game you would have me share in is a dangerous one. However, I will do my best to play the cards you have put in my hands, when the chance is given me; but it must depend on that, remember. It would be simple madness for me to originate any such idea to the countess."
Like Captain Martin, Gaspard seems not to be inventing a new metaphor, but rather invoking a familiar one.