Chapter 16. Synchronizing template repositories
In Satellite, you can synchronize repositories of job templates, provisioning templates, report templates, and partition table templates between Satellite Server and a version control system or local directory.
This section details the workflow for installing and configuring the Template Sync plugin and performing exporting and importing tasks.
16.1. Synchronizing templates with an existing repository Copy linkLink copied to clipboard!
If you store templates in a repository under a version control system, you can synchronize the templates between your Satellite Server and the repository.
In this procedure, a Git repository is used for demonstration purposes.
Procedure
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
# mkdir --parents /usr/share/foreman/.config/git
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Create a file named
config
in the new directory:touch /usr/share/foreman/.config/git/config
# touch /usr/share/foreman/.config/git/config
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Allow the
foreman
user access to the.config
directory:chown --recursive foreman /usr/share/foreman/.config
# chown --recursive foreman /usr/share/foreman/.config
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 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
# sudo --user foreman git config --global http.sslCAPath Path_To_CA_Certificate
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
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
# sudo --user foreman ssh-keygen
Copy to Clipboard Copied! Toggle word wrap Toggle overflow -
Configure your version control server with the public key from your Satellite, 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
# sudo --user foreman ssh git.example.com
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
In the Satellite web UI, provide details for your Git repository:
- Navigate to Administer > Settings.
- Click the Template Sync tab.
- Change the Branch setting to define the target branch of the repository.
- Change the Repo setting to define the repository URL.
-
If you want to use an HTTP proxy to connect to the repository, change the HTTP proxy policy setting to
Global default HTTP proxy
orCustom HTTP proxy
.
Next steps
- To import templates from your repository, continue with Section 16.3, “Importing templates”.
- To export templates to your repository, continue with Section 16.4, “Exporting templates”.
16.2. Synchronizing templates with a local directory Copy linkLink copied to clipboard!
If you store templates in a local directory that is tracked under a version control system, you can synchronize the templates between your Satellite Server and the local directory.
Prerequisites
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:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Procedure
On your Satellite Server, in
/var/lib/foreman
, create a directory for storing templates:mkdir /var/lib/foreman/My_Templates_Dir
# mkdir /var/lib/foreman/My_Templates_Dir
Copy to Clipboard Copied! Toggle word wrap Toggle overflow NoteYou 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
# chown foreman /var/lib/foreman/My_Templates_Dir
Copy to Clipboard Copied! Toggle word wrap Toggle overflow -
Change the Repo setting on the Template Sync tab to match the
/var/lib/foreman/My_Templates_Dir/
directory.
16.3. Importing templates Copy linkLink copied to clipboard!
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 Satellite are locked and you cannot import them by default. To overwrite this behavior, change the Force import
setting in the Template Sync menu to yes
or add the force
parameter -d '{ "force": "true" }'
to the import command.
Prerequisites
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:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
To use the CLI instead of the Satellite web UI, see the CLI procedure.
To use the API, see the API procedure.
To use Ansible, see the Ansible procedure.
Procedure
- In the Satellite web 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 Section B.3, “Template sync settings”.
- Click Submit.
The Satellite web UI displays the status of the import. The status is not persistent; if you leave the status page, you cannot return to it.
CLI procedure
To import a template from a repository, enter the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 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.
API procedure
Send a
POST
request toapi/v2/templates/import
:curl -H "Accept:application/json" \ -H "Content-Type:application/json" \ -u login:password \ -k https://satellite.example.com/api/v2/templates/import \ -X POST
# curl -H "Accept:application/json" \ -H "Content-Type:application/json" \ -u login:password \ -k https://satellite.example.com/api/v2/templates/import \ -X POST
Copy to Clipboard Copied! Toggle word wrap Toggle overflow If the import is successful, you receive
{"message":"Success"}
.
Ansible procedure
-
Use the
redhat.satellite.templates_import
module.
For more information, see the Ansible module documentation with ansible-doc redhat.satellite.templates_import
.
16.4. Exporting templates Copy linkLink copied to clipboard!
You can export templates to an existing repository.
To use the CLI instead of the Satellite web UI, see the CLI procedure.
To use the API, see the API procedure.
Procedure
- In the Satellite web 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 Section B.3, “Template sync settings”.
- Click Submit.
The Satellite web UI displays the status of the export. The status is not persistent; if you leave the status page, you cannot return to it.
CLI procedure
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"
$ hammer export-templates \ --organization "My_Organization" \ --repo "https://git.example.com/path/to/repository"
Copy to Clipboard Copied! Toggle word wrap Toggle overflow NoteThis 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.
API procedure
Send a
POST
request toapi/v2/templates/export
:curl -H "Accept:application/json" \ -H "Content-Type:application/json" \ -u login:password \ -k https://satellite.example.com/api/v2/templates/export \ -X POST
# curl -H "Accept:application/json" \ -H "Content-Type:application/json" \ -u login:password \ -k https://satellite.example.com/api/v2/templates/export \ -X POST
Copy to Clipboard Copied! Toggle word wrap Toggle overflow If the export is successful, you receive
{"message":"Success"}
.
You can override default API settings by specifying them in the request with the -d
parameter. The following example exports templates to the git.example.com/templates
repository: