Taharah is a real condition شرط واقعي in Prayers and fasting. Any worship which requires Purity (Taharah) is invalid if it was done with out purity.
If you could not learn basic rules of Ghusl and never been informed that Ghusl is obligatory in certain cases, which is very rare now a days, then the rule is different. But if you knew about Ghusl and it becomes obligatory in certain situations, and you did not know that it applies on you, and you fasted with out Ghusl, then you need to perform the obligatory Ghusl then perform every worship which was performed with out Ghusl.
You can read the verdict of Ayatullah Sustani as follows:
Ruling 1593. If a junub in the month of Ramadan forgets to perform ghusl and remembers after one day, he must keep a qaḍāʾ fast for that day; and if he remembers after a few days, he must keep a qaḍāʾ fast for all the days that he is certain to have been junub on. For example, if he does not know whether he was junub for three or four days, he must keep qaḍāʾ fasts for three days.