All classes can switch between DPS/tank/support depending on how they decide to trait, so this isn't a characteristic that's necessarily exclusive to the Guardian. However, you are correct in your assessment that your effectiveness in each role, in general, will be rather dependent on how you have set your traits.
When talking about Traits, we're talking about two aspects of traits, trait lines and points, and then the Minor/Major passive skills themselves. Let's talk about those for a moment before getting to the crux of your question.
Trait Lines and Points
Trait lines are profession-specific and putting points into them increases passive stats for your primary, secondary, and profession-specific attributes. This part is pretty clear, as you can clearly see that when you put points into these lines, you receive a bonus to whatever attributes are attached to that line. You open up new Minor traits at 5/15/25 points in a single trait line and once you get to 10/20/30 points into a trait line, you open up a new set of Major traits to choose from.
What may not be clear is that respeccing your trait lines is incredibly cheap and easy. At most, it will cost you 3 silver and 50 copper at level 80. In my opinion, this is cheap enough to be flexible about your build and experimenting with it.
Minor/Major Trait skills
Minor and Major trait skills, as stated, open up after you put a certain number of trait points into a single trait line. The Minor traits are static bonuses that you always get at 5/15/25. The Major traits can be mixed and matched to your liking, with more Major traits opening up at 10/20/30 points.
What some people do not notice is that you can freely change your Major traits anytime out of combat. You do not need to pay for a respec in order to change your Major traits. You can change your traits in between fights if you need to, and in some places, I'd highly recommend doing so (like dungeons, where boss strategies may require different trait sets).
Now, your question was essentially about role flexibility in regards to Traits. Let's look at your Offensive vs. Support build example. Let's say you're specced 30/30/10 into Zeal, Radiance, and Valor. For the sake of simplicity, let's just look at the passive attribute bonuses you get rather than getting into a full trait build.
This would give you:
- +300 Power/+30% Condition Duration
- +300 Precision/+300 Condition Damage
- +100 Toughness/+10% Critical Damage
For a Support build, let's say you're 30/20/20 in Valor, Honor, and Virtues, which gives the following bonuses:
- +300 Toughness/+30% Critical Damage
- +200 Vitality/+200 Healing Power
- +20% Boon Duration/+20% Virtue Recharge Rate
The first build is your straightforward glass cannon style build, while the latter is more survivability/support focused. What you may need to consider is your definition of "support". Dead enemies do no damage after all, so being able to kill them quicker may be just as beneficial for your team as if you were in a more supportive build!
There are support-oriented traits you can use in the offensive trait build:
There are also offensive-oriented traits in the supportive trait build:
- Right-Hand Strength - increase in one-handed weapon critical chance
- Glacial Heart - Critting with a hammer has a 50% chance to debuff your target with Chill
- Two-Handed Mastery - +20% recharget to 2-handed skills. If you're wielding a Greatsword, that's a nice increase to DPS
These are just a couple of example traits from each possible build, as there are others that also fit the role. Looking at this, I think you can come to the conclusion that you're not entirely locked into one role or another based solely on your traits, especially because you have the flexibility to change out the Major traits in between battles, even though you can't change your trait lines themselves without respeccing.
Now, whether or not you are as effective as someone else who has traited into the support build and thus has more support-style traits available can be up for debate. Numbers-wise, someone who has +20% Boon Duration is obviously going to have an advantage over someone who doesn't. However, numbers aren't the only metric by which you should measure your success, and I'll detail that more in the next section.
Determining success and failure
Now, whether or not you "fail" to provide the needed support for your team when you are running the offensive build is rather subjective, because it essentially boils down to What does my team need? and Am I skilled enough to provide what they need?
When looking at your team composition, you need to ask yourself a few things:
What are our goals? Are you doing just general PvE (filling hearts, doing dynamic events, zone clearing), dungeons, WvWvW, karma farming? You can "get away" with being a little lazy about your build specificity when just running around doing general PvE for zone completion, for example, but when doing dungeons, it can be advantageous to consult with your teammates about who's specced more for DPS and who's more support-oriented. While it is true that the Holy Trinity (tank/DPS/healer) doesn't necessarily have to exist in GW2, having people fill these roles at certain times certainly isn't remiss. Figure out what you're doing first, and then ask:
What do we need? Did everyone spec as a glass cannon for the dungeon run? You may end up doing a lot of reviving if people aren't careful about dodging attacks. Spending more time rezzing than fighting isn't very efficient and can kill the fun factor for a lot of people. Figure out what roles you need to fill for what you need to do then ask yourself:
Do I have the skills (both Traits and playskill) to fill the roles we need? While it's not especially evident in lower level play and zones, learning dodging, positioning, timing, and combos well will make you a vastly better player than just spamming your skills every time they're on cooldown. Learning to avoid those heavy hitting attacks means you can save time trying to get your heal off while an Champion Giant tries to beat your face in and the rest of your team is downed. Learning to take advantage of combos with your teammates can turn a fight in your favor. Having the proper traits for certain fights can help fill holes as well (Protective Reviver can be handy if you know there's a high risk of dying, Purity is good for condition-heavy fights, etc.). However, a good player will be familiar with their own strengths and weaknesses, which leads into the next section.
Flexibility is, in my opinion, the most important part of being an effective GW2 player. Because the cost of respeccing is so low, there's really no reason not to experiment with various builds and trait setups.
While you ask if you can tank/heal/DPS with the same spec, I find that a difficult question to answer, partially because I'm not sure what you consider the same spec (Same trait lines, different Major Traits? Same Major traits all the time? Different trait lines?) and partially because some players can be just as effective in an "out of role" spec (playing offensively while specced for support and vice versa, for example) due to simple playskill.
You shouldn't ever really have to feel like you're locked into one particular spec given that you can respec easily and you can change your Major traits out in between fights. Be willing to be flexible with your trait setup, both in regards to lines you use and traits you keep active. Personally, I have a different spec I use for general PvE, dungeoning, and WvWvW, and I change between them whenever I know I'm going to be doing one of them for a while. You can make up the cost of the respec by selling 3-4 level 80 blues.
Knowing your "proper role" in GW2 is not only about what particular trait lines and Major traits you have equipped, but also about whether or not you have the knowledge and skill to play effectively. Learning to balance these two will aspects will let you be the most effective.
If you're built for support but you stand there and just try to face tank a boss without dodging their heavy hitting attacks, you're not going to do much good for your team, as they'll be burning their heals on you and possibly be stuck reviving you, which may put them in danger, as they'll be standing still. So if you know you're dodging skills aren't that great in melee but you're good at standing back doing ranged DPS, switch up your spec to take advantage of your strengths! If you're traited into Spirit Weapon Mastery but you often forget to resummon them after commanding them, consider switching to a trait you can use more effectively.
If you want to be a good player, you'll learn where that balance is between effective traits and effective playskill for yourself. Good luck!
Some Extra Information:
"And it doesn’t matter if you’ve invested in traits that are initially damage focused.
Even a Zeal and Radiance type of guardian can swap around their abilities to ensure
they are still viable in group defense... The same is true in reverse! If you’re a group healer and protector, don’t believe you can’t do other things. When smaller combat erupts, be ready to break out the hammer and lock down the one annoying sucker that keeps getting away."
(Source : The Official BradyGame Guide of Guild Wars 2)