New with Sitecore 9 is the ability to specify server roles.  There is nothing new here when it comes to the roles available, however. It’s still your typical Authoring, Delivery, Processing and Reporting roles.  There is another new “role” called “Standalone” which is “all roles” such as something you’d see for a Dev Environment.

Sitecore 9 now allows you to specify (and configure!) your servers based off role.  Previously this was a whole lot of config file updating and even automated tools that would provide feedback on config files enabled/disabled due to the role.

In Sitecore 9, if you open up the web.config, you’ll see the following chunk of configuration:

<!-- SUPPORTED SERVER ROLES     
       Specify the roles that you want this server to perform. A server can perform one or more roles. Enter the roles in a comma separated list. The supported roles are:

       ContentDelivery
       ContentManagement
       Processing
       Reporting
       Standalone
          
  Default value: Standalone
-->
<add key="role:define" value="Standalone" />

This tells Sitecore that your server is configured as a Standalone server. It has all functions Sitecore needs for a single-server environment.

It’s possible to tweak this key though, and specify a list of roles, separated by a comma.   Take the below example as a standard small-scale environment for Authoring, Processing and Reporting:

<add key="role:define" value="ContentManagement, Processing, Reporting" />

That’s all neat, but what does it do?  The big answer is…role-specific configs!

If you open up the /App_Config/Sitecore/CMS.Core/Sitecore.WebDAV.config” (which is something you disable on delivery servers as part of common practice) you see this at the top:

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:role="http://www.sitecore.net/xmlconfig/role/">
  <sitecore role:require="Standalone or ContentManagement">

You can see that Sitecore is going to only patch this config in when the role is CM or Standalone.

Additionally, you can do this at the element level. For example, the master DB belongs only on the CM server.  Here’s how Sitecore has this configured out of the box:

<database id="master" role:require="Standalone or ContentManagement">

Pretty slick!  This is a huge amount of flexibility and will make environment management SO much easier.

PS: Sitecore 9 doesn’t ship with a way to check the current server roles via code, but the method below should allow you to do just that. It leverages some of the lines from the current ConfigReader.

public bool HasRole(SitecoreRole role)
{
	var appSetting = ConfigurationManager.AppSettings["role:define"];

	var splits = appSetting.Split("|,;".ToCharArray()).Select(r => Regex.Match(r, "^\\s*(\\S*)\\s*$").Groups[1].Value).Where(s => s.Length > 0).Select(x => x.ToLowerInvariant()).Distinct().ToArray();

	if (splits.Length == 0)
		return true;

	return splits.Contains(role.Name.ToLower()) || splits.Contains("standalone");
}

[ls_content_block slug=”nineonninefooter”]