Using policy templates

If you use large policies that contain multiple repeatable values, or want to move a policy from one environment to another more quickly, you can use the template processing feature that is provided by the sampolicy command.

Instead of actual values, you use parameters in the XML file that look like %%parname%%, where parname is the name of the parameter. The parameter must be defined in the var element of the XML policy template file.

The element has the following attributes:
name
Name of parameter.
value
Value of the parameter.

You can use one parameter in many places and in multiple files but need to change it only in one place. It helps in migrating the policy from one environment to another.

Additionally, it is possible to include other XML files in the XML policy template file which makes working with an XML policy template very comfortable.

You can attach new XML files using the include element. Its node value must contain the path to the attached file; the path can be relative.

The template XML file has a different root element: AutomationPolicyTemplate. If you want to activate or update a policy using templates you must use the -t parameter with the sampolicy command.

Example:
sampolicy -a -t top.xml
Contents of a top.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<AutomationPolicyTemplate productID="SAM" version="4.1.0"
          xmlns="http://www.ibm.com/TSA/Policy.xsd" 
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
          xsi:schemaLocation="http://www.ibm.com/TSA/Policy.xsd 
          SAMPolicyTemplate.xsd ">
    <PolicyInformation>
        <PolicyName>template</PolicyName>
        <AutomationDomainName>%%domain%%</AutomationDomainName>
        <PolicyToken>1.0</PolicyToken>
        <PolicyDescription>MyDescription</PolicyDescription>
         <PolicyAuthor>admin</PolicyAuthor>
    </PolicyInformation>
    <var name="domain" value="lnx"/> 
    <var name="node1" value="lnxcm11x"/> 
    <include>internal.xml</include> 
</AutomationPolicyTemplate>
Contents of internal.xml:
<?xml version="1.0" encoding="UTF-8"?>
<AutomationPolicy productID="SAM" version="4.1.0" 
          xmlns="http://www.ibm.com/TSA/Policy.xsd" 
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
          xsi:schemaLocation="http://www.ibm.com/TSA/Policy.xsd 
          SAMPolicy.xsd"> 

    <ControlInformation> 
        <Timeout>60</Timeout> 
        <RetryCount>3</RetryCount> 
        <ResourceRestartTimeout>5</ResourceRestartTimeout>
    </ControlInformation>
    <Resource name="T1" class="IBM.Test" node="%%node1%%"> 
        <ClassAttributesReference>
            <IBM.TestAttributes name="IBM.Test.T1"/> 
        </ClassAttributesReference>
    </Resource>
    <IBM.TestAttributes name="IBM.Test.T1" > 
         <TimeToStart>0</TimeToStart> 
         <TimeToStop>0</TimeToStop> 
         <WriteToSyslog>0</WriteToSyslog>
    </IBM.TestAttributes>
</AutomationPolicy> 

The policy shown above will create a simple IBM.Test resource using templates. The resulting XML policy will contain all included XML files and the substituted parameters. It will be saved in the current folder with the name of the top-level file and the and the added suffix .complete.tmp.

The file top.xml.complete.tmp that is generated from the two example files above (top.xml and internal.xml), using the command sampolicy -a -t top.xml looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<AutomationPolicy productID="SAM" version="4.1.0"
          xmlns="http://www.ibm.com/TSA/Policy.xsd"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://www.ibm.com/TSA/Policy.xsd SAMPolicy.xsd">

    <PolicyInformation>
        <PolicyName>template</PolicyName>
        <AutomationDomainName>lnx</AutomationDomainName>
        <PolicyToken>1.0</PolicyToken>
        <PolicyDescription>MyDescription</PolicyDescription>
        <PolicyAuthor>admin</PolicyAuthor>
    </PolicyInformation>

    <ControlInformation>
        <Timeout>60</Timeout>
        <RetryCount>3</RetryCount>
        <ResourceRestartTimeout>5</ResourceRestartTimeout>
    </ControlInformation>

    <Resource name="T1" class="IBM.Test" node="lnxcm11x">
        <ClassAttributesReference>
        <IBM.TestAttributes name="IBM.Test.T1"/>
        </ClassAttributesReference>
    </Resource>

    <IBM.TestAttributes name="IBM.Test.T1" >
        <TimeToStart>0</TimeToStart>
        <TimeToStop>0</TimeToStop>
        <WriteToSyslog>0</WriteToSyslog>
    </IBM.TestAttributes>

</AutomationPolicy>