To be honest I usually use the monitor wrapper in my setups, with top scope variables like:
$monitor = true
$monitor_tool = [ 'puppi' , 'icinga' ]
(Puppi as monitor_tool allows you to run locally on the server, with the command "puppi check" the same checks you'll find on Icinga)
That's enough for all the nodes (when they use Example42 modules),
on the Icinga server you basically just need:
include icinga
There are then various options on how to configure the monitoring.
Automatic Hostgroups management is a bit a PITA, the icinga module provides the possibility to create automatically hostgroups according to a custom variable, for example you may set (at top scope) something like:
$::icinga_hostgrouplogic = 'role'
and on your Icinga server automatic hostgroup for each role should be created.
To create custom hostgroups use
icinga::hostgroup (on the Icinga server)
and to assign a node to an host group use the hostgroup parameters in icinga::host (on the monitored node)
Actually your piece of code should work.