Ah, sorry, I missed that bit of detail in your original posting.
So, test1 gets applied to the (previously defined) Host, at which time Icinga
knows all about the properties of that Host, therefore it picks up the
ssh_username value correctly.
But test2 is simply defined, and not applied to a host, so Icinga doesn’t
know what the properties of Host example1 are when test2 is being defined,
therefore it can’t get a value for ssh_username.
That’s one of the advantages of using apply rules.
And that’s exactly the problem here. With apply rules, you’ll virtually get access to the host variable and can use that in this scope. With just creating a service object, no such reference exists yet at this point during config compilation.