Satellite 6.3 Feature Overview: Pull Templates from GIT

Updated -

Satellite 6.3 enables synchronization of Job Templates, Provisioning Templates, and Partition Table Templates between Satellite Server and a Git repository or a local directory.
This capability is covered in the Satellite 6.3 Content Management Guide in Appendix E: Synchronizing Templates with Git.

Much of the content in this feature overview comes from Appendix E above - be sure to read that section for complete information about this feature.

The workflow for using templates with Git is broken into three primary steps:

  • Enabling the TemplateSync plug-in
  • Configuring the TemplateSync plug-in
  • Importing and exporting Templates

Enabling the TemplateSync plug-in

The TemplateSync plug-in needs to be enabled post Satellite install.
To do so, execute the following command:

# satellite-installer --enable-foreman-plugin-templates

To verify that the plug-in is correctly installed, log into the Satellite Web UI then navigate to Administer → Settings, then make sure you see the TemplateSync menu.

Configuring the TemplateSync plug-in

Navigate to Administer → Settings → TemplateSync to configure the plug-in. The following table explains the attributes behavior. Note that some attributes are only used on importing or exporting tasks.

Table E.1 in Appendix E of the Content Management Guide lists all of the parameters and their meanings. Please refer to that table for full details.

Importing and exporting Templates

Importing and exporting tasks are available through a series of API calls. API calls use the role-based access control system, which enables the tasks to be executed as any user. The TemplateSync plug-in allows synchronizing with a Git repository or a local directory.

Synchronizing Templates with a Git repository

  1. Configure a Git server that uses SSH authorization, for example gitosis, gitolite, or git daemon.
  2. Configure the TemplateSync plug-in settings on a TemplateSync tab.
    1. Change the Branch setting to match the target branch on a Git server.
    2. 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 into ssh://git@git.example.com/templates.git.
  3. Accept Git SSH host key as the foreman user:

    # sudo -u foreman ssh git.example.com
    

    You will see the Permission denied, please try again. message in the output, which is expected, because the SSH connection cannot succeed yet.

  4. Create an SSH key pair if you do not already have it. Do not specify any passphrase.

    # sudo -u foreman ssh-keygen
    
  5. Configure your Git server with the public key from your Satellite, which resides in /usr/share/foreman/.ssh/id_rsa.pub.

  6. Export templates from your Satellite Server to the Git repository specified in the TemplateSync menu:

    $ curl -H "Accept:application/json,version=2" 
    -H "Content-Type:application/json" 
    -u login:password 
    -k https://satellite.example.com/api/v2/templates/export
    -X POST
    
    {"message":"Success"}
    
  7. Import templates to the Satellite Server after their content was changed:

    $ curl -H "Accept:application/json,version=2" \
    -H "Content-Type:application/json" \
    -u login:password \
    -k https://satellite.example.com/api/v2/templates/import \
    -X POST
    
    {“message”:”Success”}
    

    Note that templates provided by Satellite are locked and you cannot import them by default. To overwrite this behavior, change the Force import setting in the TemplateSync menu to yes or add the force parameter -d '{ "force": "true" }’ to the import command.

Synchronizing templates with a local directory

Synchronizing templates with a local directory is useful if you have configured any revision control system 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 the Satellite after editing the templates.

  1. Create the directory where templates will be stored and apply appropriate permissions and SELinux context:

    # mkdir -p /usr/share/templates_dir/
    # chown foreman /usr/share/templates_dir/
    # chcon -t httpd_sys_rw_content_t /usr/share/templates_dir/ -R
    
  2. Change the Repo setting on the TemplateSync tab to match the export directory /usr/share/templates_dir/.
  3. Export templates from your Satellite Server to a local directory:

    $ curl -H "Accept:application/json,version=2" \
    -H "Content-Type:application/json" \
    -u login:password \
    -k https://satellite.example.com/api/v2/templates/export \
    -X POST \
    
    {"message":"Success"}
    
  4. Import templates to the Satellite after their content was changed:

    $ curl -H "Accept:application/json,version=2" \
    -H "Content-Type:application/json" \
    -u login:password \
    -k https://satellite.example.com/api/v2/templates/import \
    -X POST
    
    {“message”:”Success”}
    

    Note that templates provided by Satellite are locked and you cannot import them by default. To overwrite this behavior, change the Force import setting in the TemplateSync menu to yes or add the force parameter -d '{ "force": "true" }’ to the import command.

NOTE

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:

    $ curl -H "Accept:application/json,version=2" \
    -H "Content-Type:application/json" \
    -u login:password \
    -k https://satellite.example.com/api/v2/templates/export \
    -X POST \
    -d "{\"repo\":\"git.example.com/templates\"}"

Please reference Appendix E of the Content Management Guide for advanced Git configurations as well as information on how to uninstall the TemplateSync plug-in.

Comments