Add role-specific configs to sitecore

As part of some requirements, we need to add configs to only specific roles and make sure that it is not added to other roles. For example, in one of the implementations, the requirement was to add a patch only on the content delivery (CD) or Standalone server but not on the content management (CM).

One of the ways to do this is to configure the release pipeline such that the config is only deployed to the CD server and not to the CM server.

The other way to achieve the same is to add a condition in the patch config file itself as shown below –

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

In the above configuration, I added the role:require configuration as well as xmlns:role node to make sure that the patch is added only to the ContentDelivery or Standalone role.

For the above configuration to work properly, make sure that role is correctly defined in the web.config file on each environment.

 <!-- 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
         ContentDelivery, Indexing
         ContentManagement, Indexing
         Processing
         Reporting
         Standalone
          
    Default value: Standalone
    -->
    <add key="role:define" value="ContentDelivery"/>