Skip to content

Latest commit

 

History

History
81 lines (72 loc) · 2.83 KB

proc_importing-templates.adoc

File metadata and controls

81 lines (72 loc) · 2.83 KB

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.

Note

The templates provided by {Project} 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.

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:

    <%#
    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 {ProjectWebUI}, see the CLI procedure. To use the API, see the API Procedure.

Procedure
  1. In the {ProjectWebUI}, navigate to Hosts > Templates > Sync Templates.

  2. Click Import.

  3. Each field is populated with values configured in Administer > Settings > TemplateSync. Change the values as required for the templates you want to import. For more information about each field, see [Configuring_the_TemplateSync_plugin_{context}].

  4. Click Submit.

The {ProjectWebUI} 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:

    $ 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.

API Procedure
  1. Send a POST request to api/v2/templates/import:

    # curl -H "Accept:application/json" \
    -H "Content-Type:application/json" \
    -u login:password \
    -k https://{foreman-example-com}/api/v2/templates/import \
    -X POST

    If the import is successful, you receive {"message":"Success"}.