Hitler was receiving proposals to occupy Gibraltar already before the collapse of France in 1940. The occupation of Gibraltar was combined with the occupation of Suez and the exclusion of the British from the Mediterranean. If this plan had been followed the course of the war would probably have been different.
On July 12, 1940 Hitler sent to Madrid the head of the intelligence service Admiral Willem Canaris where he met with Franco and the Spanish Minister of War. Then Canaris came all the way to Gibraltar gazing at the famous "Rock".
Franco was reluctant to enter the war anyway, and Canaris discouraged him by playing his own game against Hitler ever since. In his report to Berlin Kanaris was also hesitant stating that the capture of Gibraltar required at least two German infantry regiments, three engineer battalions and 12 artillery regiments.
All of these were readily available. However, the 380 mm guns were not available. (15 inches) which he considered necessary for the exhumation of the "Rock". At the same time, he raised other, logical, obstacles, clarifying that if Germany occupied Gibraltar, the British would occupy Morocco and French West Africa.
In August 1940 Canaris met with Ramon Serrano Sounier , who would shortly take over as Spain's foreign ministerand asked him to do everything he could to keep Spain out of the war . A little later Franco sent Sounier to Berlin to spy on Hitler.
Hitler did not in this case press the Spanish minister for the exit of Spain to the war, aspiring to convince Franco with whom a meeting was arranged. At the same time Canaris met with Franco, warning him that if Spain joined the Axis, it would soon lose, in the first phase, all its islands.
Franco countered his fears of a German invasion of Spain if he did not cooperate with Hitler. But Kanaris reassured him by revealing that Hitler was planning an attack on the Soviet Union. He also emphasized to Franco that, in his opinion, Germany could not win the war...
So when the German ambassador in Madrid was the last to approach Franco, to include his country in the Axis and participate in an attack on Gibraltar, he set unrealistic terms which he knew Hitler could not accept. One of them was the realization, first, of a German landing in England...
An enraged Hitler, unbeknownst to him, again sent Canaris to Madrid to persuade Franco. Canaris again pointed out to Franco that he would be too stupid to side with the power that would, with mathematical precision, lose the war, namely Germany.
In the meantime Hitler approved the general plan for the occupation of Gibraltar that was presented to him. But everything came crashing down when, on October 24, 1940, he met with Franco in Hentaie. Then he himself proposed to Franco the inclusion of Spain in the Axis. Soon, however, he was exasperated listening to his interlocutor expressing doubts about the German victory over Britain.
Franco, boldly, told the German dictator that even if he occupied the British Isles, the British Empire was impossible to defeat. "I'd rather have four teeth pulled out than to meet Franco again". , Hitler wrote to Mussolini after the meeting.
However, Hitler did not forget the plan for Gibraltar (Operation Felix). He returned in November 1940 and on 5 December told his generals that he would request permission for the passage of German forces from Franco, with a view to launching the offensive in January 1941.
Canaris again went to Madrid to "convince" Franco, who, of course, refused to be convinced. Diplomatic pressures from Berlin and Rome on Franco followed, but they did not work. Spain stayed out of the war, Hitler never took Gibraltar, nor did he "seal" the Mediterranean.