Synchronizing template repositories
In orcharhino, you can synchronize repositories of job templates, provisioning templates, report templates, and partition table templates between orcharhino Server and a version control system or local directory. In this chapter, a Git repository is used for demonstration purposes.
This section details the workflow for installing and configuring the Template Sync plugin and performing exporting and importing tasks.
Enabling the Template Sync plugin
-
To enable the plugin on your orcharhino Server, enter the following command:
$ orcharhino-installer --enable-foreman-plugin-templates
-
To verify that the plugin is installed correctly, ensure Administer > Settings includes the Template Sync menu.
-
Optional: In the orcharhino management UI, navigate to Administer > Settings > Template Sync to configure the plugin. For more information, see Template sync settings in Administering orcharhino.
Using repository sources
You can use existing repositories or local directories to synchronize templates with your orcharhino Server.
Synchronizing templates with an existing repository
Use this procedure to synchronize templates between your orcharhino Server and an existing repository.
-
If you want to use HTTPS to connect to the repository and you use a self-signed certificate authority (CA) on your Git server:
-
Create a new directory under the
/usr/share/foreman/
directory to store the Git configuration for the certificate:$ mkdir --parents /usr/share/foreman/.config/git
-
Create a file named
config
in the new directory:$ touch /usr/share/foreman/.config/git/config
-
Allow the
foreman
user access to the.config
directory:$ chown --recursive foreman /usr/share/foreman/.config
-
Update the Git global configuration for the
foreman
user with the path to your self-signed CA certificate:$ sudo --user foreman git config --global http.sslCAPath Path_To_CA_Certificate
-
-
If you want to use SSH to connect to the repository:
-
Create an SSH key pair if you do not already have it. Do not specify a passphrase.
$ sudo --user foreman ssh-keygen
-
Configure your version control server with the public key from your orcharhino, which resides in
/usr/share/foreman/.ssh/id_rsa.pub
. -
Accept the Git SSH host key as the
foreman
user:$ sudo --user foreman ssh git.example.com
-
-
Configure the Template Sync plugin settings on a Template Sync tab.
-
Change the Branch setting to match the target branch on a Git server.
-
Change the Repo setting to match the Git repository. For example, for the repository located in
git@git.example.com/templates.git
set the setting intogit@git.example.com/templates.git
.
-
Synchronizing templates with a local directory
Synchronizing templates with a local directory is useful if you have configured a version control repository in the local directory. That way, you can edit templates and track the history of edits in the directory. You can also synchronize changes to orcharhino Server after editing the templates.
-
Each template must contain the location and organization that the template belongs to. This applies to all template types. Before you import a template, ensure that you add the following section to the template:
<%# kind: provision name: My_Provisioning_Template oses: - My_first_OS - My_second_OS locations: - My_first_Location - My_second_Location organizations: - My_first_Organization - My_second_Organization %>
-
In
/var/lib/foreman
, create a directory for storing templates:$ mkdir /var/lib/foreman/My_Templates_Dir
You can place your templates to a custom directory outside
/var/lib/foreman
, but you have to ensure that theForeman
service can read its contents. The directory must have the correct file permissions and theforeman_lib_t
SELinux label. -
Change the owner of the new templates directory to the
foreman
user:$ chown foreman /var/lib/foreman/My_Templates_Dir
-
Change the Repo setting on the Template Sync tab to match the
/var/lib/foreman/My_Templates_Dir/
directory.
Importing and exporting templates
You can import and export templates using the orcharhino management UI, Hammer CLI, or orcharhino API. orcharhino API calls use the role-based access control system, which enables the tasks to be executed as any user. You can synchronize templates with a version control system, such as Git, or a local directory.
Importing templates
You can import templates from a repository of your choice.
You can use different protocols to point to your repository, for example /tmp/dir
, git://example.com
, https://example.com
, and ssh://example.com
.
The templates provided by orcharhino are locked and you cannot import them by default.
To overwrite this behavior, change the |
-
Each template must contain the location and organization that the template belongs to. This applies to all template types. Before you import a template, ensure that you add the following section to the template:
<%# kind: provision name: My_Provisioning_Template oses: - My_first_OS - My_second_OS locations: - My_first_Location - My_second_Location organizations: - My_first_Organization - My_second_Organization %>
To use the CLI instead of the orcharhino management UI, see the CLI procedure. To use the API, see the API procedure.
-
In the orcharhino management UI, navigate to Hosts > Templates > Sync Templates.
-
Click Import.
-
Each field is populated with values configured in Administer > Settings > Template Sync. Change the values as required for the templates you want to import. For more information about each field, see Template sync settings in Administering orcharhino.
-
Click Submit.
The orcharhino management UI displays the status of the import. The status is not persistent; if you leave the status page, you cannot return to it.
-
To import a template from a repository, enter the following command:
$ hammer import-templates \ --branch "My_Branch" \ --filter '.*Template Name$' \ --organization "My_Organization" \ --prefix "[Custom Index] " \ --repo "https://git.example.com/path/to/repository"
For better indexing and management of your templates, use
--prefix
to set a category for your templates. To select certain templates from a large repository, use--filter
to define the title of the templates that you want to import. For example--filter '.*Ansible Default$'
imports various Ansible Default templates.
-
Send a
POST
request toapi/v2/templates/import
:$ curl -H "Accept:application/json" \ -H "Content-Type:application/json" \ -u login:password \ -k https://orcharhino.example.com/api/v2/templates/import \ -X POST
If the import is successful, you receive
{"message":"Success"}
.
Exporting templates
Use this procedure to export templates to a git repository.
To use the CLI instead of the orcharhino management UI, see the CLI procedure. To use the API, see the API procedure.
-
In the orcharhino management UI, navigate to Hosts > Templates > Sync Templates.
-
Click Export.
-
Each field is populated with values configured in Administer > Settings > Template Sync. Change the values as required for the templates you want to export. For more information about each field, see Template sync settings in Administering orcharhino.
-
Click Submit.
The orcharhino management UI displays the status of the export. The status is not persistent; if you leave the status page, you cannot return to it.
-
To export the templates to a repository, enter the following command:
$ hammer export-templates \ --organization "My_Organization" \ --repo "https://git.example.com/path/to/repository"
This command clones the repository, makes changes in a commit, and pushes back to the repository. You can use the
--branch "My_Branch"
option to export the templates to a specific branch.
-
Send a
POST
request toapi/v2/templates/export
:$ curl -H "Accept:application/json" \ -H "Content-Type:application/json" \ -u login:password \ -k https://orcharhino.example.com/api/v2/templates/export \ -X POST
If the export is successful, you receive
{"message":"Success"}
.
You can override default API settings by specifying them in the request with the
|
Uninstalling the Foreman templates plugin
Use the following procedure to avoid errors after removing the foreman_templates plugin.
-
Disable the plugin using the orcharhino installer:
$ orcharhino-installer --no-enable-foreman-plugin-templates
-
Clean custom data of the plugin. The command does not affect any templates that you created.
$ foreman-rake templates:cleanup
-
Uninstall the plugin:
$ dnf remove foreman-plugin-templates
The text and illustrations on this page are licensed by ATIX AG under a Creative Commons Attribution Share Alike 4.0 International ("CC BY-SA 4.0") license. This page also contains text from the official Foreman documentation which uses the same license ("CC BY-SA 4.0"). |