is this the same as in hostgroups? maybe extract to a mixin/class?