<commit_before>= Templates
{product-author}
{product-version}
:data-uri:
:icons:
:experimental:
:toc: macro
:toc-title:

toc::[]

== Overview
A template describes a set of resources intended to be used together that can be customized and processed to produce a configuration. Each template can define a list of parameters that can be modified for consumption by containers. It can also define a set of labels to apply to every resource created by the template.

== Parts of a Template
.Following is a sample template JSON file:

----
{
  "apiVersion": "v1beta1",
  "kind": "Template",
  "metadata": {
    "name": "templateName", <1>
    "annotations": {
      "description": "Description of the template" <2>
    }
  },
  "parameters": [ <3>
    {
      "name": "username"
      "value": "admin"
      "description": "administrative user"
    }
  ],
  "labels": { <4>
    "custom_label": "custom_label_value"
  },
  "items": [ <5>
    {
      ...
    }
  ]
}
----

<1> The name of the template
<2> Optional description for the template
<3> A list of parameters for the template
<4> A list of labels to apply to resources
<5> A list of resources to create

== Labels
The list of labels specified in the template will be applied to every resource that is generated from the template. link:../architecture/kubernetes_model.html#label[Labels] can be used to manage and organize generated resources.

== Parameters
The list of parameters that you want to override are listed in the *parameters* section of the template. Alternatively, you can override them with the following command, specifying the file to be used:

****
`osc process --parameters -f [replaceable]#<filename>#`
****

The following shows the output when listing the parameters for one of the [replaceable]#openshift/origin/examples# template.

.Example Template Output
====
----
$ osc process --parameters -f examples/sample-app/application-template-dockerbuild.json
NAME                  DESCRIPTION              GENERATOR           VALUE
ADMIN_USERNAME        administrator username   expression          admin[A-Z0-9]{3}
ADMIN_PASSWORD        <PASSWORD>   expression          [a-zA-Z0-9]{8}
MYSQL_ROOT_PASSWORD   database password        expression          [a-zA-Z0-9]{8}
MYSQL_DATABASE        database name                                root
----
====

The output identifies several parameters that are generated with a regex expression generator when the template is processed.

== Generating a Configuration
A configuration results when a template is processed. You can override the parameters with the values defined in the configuration file by adding the appropriate flags.

You can generate a configuration with the following command:

****
`osc process -f [replaceable]#<filename>#`
****

Continuing with the previous example, you can override [envar]#ADMIN_USERNAME# and [envar]#MYSQL_DATABASE# environment variables to create a JSON string that can be applied to the server. The JSON string represents a configuration with customized environment variables, as shown in the following example.

.Generating a Configuration
====
----
$ osc process -f examples/sample-app/application-template-dockerbuild.json -v ADMIN_USERNAME=root,MYSQL_DATABASE=admin
----
====

The JSON string can either be redirected to a file or applied directly by piping the process output to the `apply` command, as shown in the following example.

.Redirecting JSON String
====
----
$ osc process -f examples/sample-app/application-template-dockerbuild.json -v ADMIN_USERNAME=root,MYSQL_DATABASE=admin | osc apply -f -
----
====<commit_msg>Sentence and format edits to templates file<commit_after>= Templates
{product-author}
{product-version}
:data-uri:
:icons:
:experimental:
:toc: macro
:toc-title:

toc::[]

== Overview
A template describes a set of resources intended to be used together that can be customized and processed to produce a configuration. Each template defines a list of parameters that can be modified for consumption by containers. It also defines a set of labels to apply to every resource created by the template.

.Sample Template JSON File:
====

----
{
  "apiVersion": "v1beta1",
  "kind": "Template",
  "metadata": {
    "name": "Template_Name", <1>
    "annotations": {
      "description": "Description" <2>
    }
  },
  "parameters": [ <3>
    {
      "name": "username"
      "value": "admin"
      "description": "administrative user"
    }
  ],
  "labels": { <4>
    "custom_label": "Label_Name"
  },
  "items": [ <5>
    {
      ...
    }
  ]
}
----

<1> The name of the template
<2> Optional description for the template
<3> A list of parameters for the template
<4> A list of labels to apply to resources
<5> A list of resources to create

====

== Labels
link:../architecture/kubernetes_model.html#label[Labels] are used to manage and organize generated resources, such as pods. The labels specified in the template are applied to every resource that is generated from the template.

== Parameters
The list of parameters that you can override are listed in the `*parameters*` section of the template. Alternatively, you can override them with the following command, specifying the file to be used:

****
`$ osc process --parameters -f _<filename>_`
****

The following shows the output when listing the parameters for one of the *_openshift/origin/examples_* templates.

.Example Template Output
====

----
$ osc process --parameters -f examples/sample-app/application-template-dockerbuild.json
NAME                  DESCRIPTION              GENERATOR           VALUE
ADMIN_USERNAME        administrator username   expression          admin[A-Z0-9]{3}
ADMIN_PASSWORD        <PASSWORD> password   expression          [a-zA-Z0-9]{8}
MYSQL_ROOT_PASSWORD   database password        expression          [a-zA-Z0-9]{8}
MYSQL_DATABASE        database name                                root
----

====

The output identifies several parameters that are generated with a regex expression generator when the template is processed.

== Generating a Configuration
When OpenShift processes a template, it creates a configuration. You can override the parameters with the values defined in the configuration file by adding the appropriate flags.

Generate a configuration with the following command:

****
`osc process -f _<filename>_`
****

Continuing with the previous example, you can override the *`ADMIN_USERNAME`* and *`MYSQL_DATABASE`* environment variables to create a JSON string to apply to the server. The JSON string represents a configuration with customized environment variables, as shown in the following example.

.Generating a Configuration
====

----
$ osc process -f examples/sample-app/application-template-dockerbuild.json -v ADMIN_USERNAME=root,MYSQL_DATABASE=admin
----

====

The JSON string can either be redirected to a file or applied directly by piping the process output to the `apply` command, as shown in the following example.

.Redirecting JSON String
====

----
$ osc process -f examples/sample-app/application-template-dockerbuild.json -v ADMIN_USERNAME=root,MYSQL_DATABASE=admin | osc apply -f -
----

====
{'fraction_non_alphanumeric': 0.09539196403484125, 'fraction_numerical': 0.005900533857825232, 'mean_word_length': 3.52, 'pattern_counts': {'":': 26, '<': 29, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2622517', 'n_tokens_mistral': 1928, 'n_tokens_neox': 1888, 'n_words': 809}