Is Gandalf actually male though? I didn't dig deep enough into the lore to know that, but I do know that he is far different from your regular human/hobbit/dwarf-person. He does present as male, but that might just be a reflection of the societies he is more-or-less living in (i.e. the old wise man persona just makes sense for practical reasons).
They wore the guise of one for longer than many live. In that time he would have been treated and lived as one with mortals who wouldn't know enough to think otherwise. If this is how he choose to live I see no reason to question it.
Well since everyone was like "how do we get that dawg back in him" and Gandalf was the only one that thought to put a sword in his hand maybe Gandalf is the only one that is male.
The Ainur are immortal, angelic beings, nonetheless they do possess gender. Those who later descended to Arda took on common male and female forms to appear to the Elves in, and have an inherent male or female gender even when formless. This is because their gender is based on their being, which is independent of any physical form they may assume.
The Ainur comprise of the Valar (godlike/archangel entities such as Morgoth, Manwe, Ulmo) and the Maiar (less powerful, notables include: Gandalf, Sauron, Saruman, Melian, all Balrogs). So this information should apply to both groups.
Excellent thank you. Cited on the wiki too - neat.
So I take this as an affirmative to my original suspicion - given they can change form at will, they could be any sex they like today, tomorrow and then be a tree the day after I guess? So they do just use the analog to represent themselves, as their existence is not constrained by such biological limitations like "sex" and they would be even less constrained by societal structures like gender!
Strange, I take the exact opposite reading of that quote: They do each have a gender identity regardless of form (or lack thereof), and can take physical form of their choosing. Yes they can change form (incl outward-presenting sex) -- that is, they have the metaphysical power to do so -- but AFAIK* there are no instances of an ainur choosing a physical form with a sex that is incongruent with their gender identity. I.E., they are always cisgender in the legendarium.
* I feel like there was one instance of someone taking a disguise of another differently-genedered character but I can't recall who it was or if I'm imagining this.
As for societal gender, it absolutely exists in Tolkien's world amongst most of the races/societies that we have exposure to.
Humans (and therefore hobbits) have gender roles generally consistent with that of European societies' "mainstream" that Tolkien was familiar with as an Englishman.
As an example for the Elves, male elves tend to be the ones that prepare food. As an "exception proves the rule" example, Galadriel partook in sufficiently male activities enough to be called Nerwen "Man-maiden", though I take this to be akin to describing a "tomboy" (but to the maximal degree, as Galadriel never does anything subtly).
There's definitely a gender division amongst Ents such that there are literally no female ents in the story except as a group which is explictly missing -- all Ents that are known to exist are by definition male/masculine in their society.
Dwarves are probably the closest to "no gender" in a Tolkien culture. But then again, every Dwarf which goes outside of their realms is said to be male so it seems like there is at least a gender role divide of "dwarf men go adventuring around the world; dwarf women stay in the city"
* As previously mentioned, there are Maiar such as Melian who married and gave birth to half-Maiar+Elven children, and also all of the Valar except 2 paired up and married each other in "heterogender" couples, maintaining the status quo of Tolkein's time amongst even the highest order of beings. It's hard to say how their gender identity expresses itself as societal gender roles since it is a such a small culture with only very specific examples given, but I think it is also generally true that male and female Valar fit vaguely into western European mythological tropes in a yin/yang sense: Yavanna (female) is "goddess" of trees and plants and her husband Aule (male) is "god" of mountains, crafting, etc.
* Edited to add some Ainur examples! We started this conversation explictly about Maiar/Valar/Ainur and I went off track to talk about the non-celestial races. Sorry about that.