Skip to navigation

iagctl db import

Import resources and services from a file.

The iagctl db import command imports services and resources from a service configuration file. Use this command to move services and resources from one gateway instance to another, or to import a file you’ve created manually.

You can import from a local file or from a repository. Gateway also provides the --validate and --check flags to verify the import before applying changes.

Syntax

iagctl db import <filename> [flags]

Usage notes

Validate an import

Use the --validate flag to verify that all resources in the file contain the required fields. If any fields are missing, the gateway returns details so you can resolve the issue.

Preview an import

Use the --check flag to preview the actions the gateway would take without making any changes. The gateway reports one of three states for each resource:

StateDescription
ConflictA resource with the same name already exists. The gateway takes no action unless you also use the --force flag.
AddThe resource is new and the gateway creates it on import.
ReplacementThe resource replaces an existing one. This state appears when you combine --check with --force.

Force an import

Use the --force flag to override any existing resources that conflict with the imported file.

If the import file contains secrets, --force replaces any existing secret that has the same name. Run the command with --check first to review the Replacement entries.

Provide credentials for a repository

The iagctl db import command clones the repository directly and requires the actual credential on the command line. It doesn’t accept secret names from the Gateway secret store. Use --private-key with the path to an SSH private key file, or use --username and --password for HTTP and HTTPS repositories.

In client mode, iagctl reads the --private-key file on the client, not on the server.

To keep tokens out of your shell history, supply the value from an environment variable or pipeline secret, for example --password "$GIT_TOKEN".

The --password-name and --private-key-name flags belong to iagctl create repository, which stores secret names that the server resolves when services run. Repositories defined inside an import file can still reference secrets by name with the password-name or private-key-name keys. Gateway resolves those secrets when services run.

For more information, see Configure access to private repositories and Use SSH keys to clone git repositories.

Secrets and users in import files

An import file created with iagctl db export can include encrypted secrets and users. Gateway imports these along with services and resources.

Examples

Import from a local file

iagctl db import ./file.yml

Import from a repository

iagctl db import import.yml --repository https://github.com/itential/quick.git

Import from a repository over SSH with a private key

The --private-key flag takes the file path of the SSH private key. In client mode, the file must exist on the client:

iagctl db import import.yml --repository git@github.com:itential/quick.git \
--private-key my-private-key-filepath

Import from a repository over HTTP or HTTPS with a username and password

iagctl db import import.yml --repository https://github.com/itential/quick.git \
--username username \
--password password-value

Validate a service file

iagctl db import ./file.yml --validate

Preview an import

iagctl db import ./file.yml --check

Preview a forced import

iagctl db import ./file.yml --check --force

Service file format

The following example shows the structure of a service configuration file:

decorators:
- name: ansible-xr
schema:
$id: https://example.com/device.schema.json
$schema: https://json-schema.org/draft/2020-12/schema
properties:
device_type:
description: The type of device
enum:
- ios
- eos
- nxos
type: string
host:
description: The hostname or IP address of the device
type: string
title: Network Device
type: object
repositories:
- name: xr-resources
description: XR Resources for testing
url: git@gitlab.com:jh/xr/resources.git
reference: main
tags:
- cisco
- xr
private-key-name: xr-gitlab-private
- name: xr-https-resources
description: XR resources over HTTPS
url: https://gitlab.com/<org>/xr/resources.git
reference: main
username: gitlab-user
password-name: xr-gitlab-token
services:
- name: Ansible-Example
type: ansible-playbook
description: An ansible playbook to say hello-world
playbooks:
- hello-world.yml
working-directory: ./
repository: xr-resources
decorator: ansible-xr
tags:
- xr
- cisco
runtime:
check: true
diff: true
skip-tags: example-tag
inventory:
- ./inventory.ini
verbose-level: 6
- name: Hello-World
type: python-script
description: A simple hello-world script
filename: hello-world.py
working-directory: python-scripts
repository: xr-resources
decorator: my-special-decorator
secrets:
- name: my-secret
type: env
target: MY_SECRET

The filename value in a service definition is a path relative to the service’s working-directory. The working-directory key is the equivalent of the --working-dir flag in iagctl create service. In the example above, Gateway runs python-scripts/hello-world.py from the xr-resources repository.

Options

--check Validate and preview the import without making changes.
--force Override any existing resources that conflict with the import.
-h, --help Help for import
--password string The password to use when authenticating with HTTP or HTTPS.
--private-key string The SSH private key file path to use when authenticating over SSH.
--reference string The reference to check out within the repository (for example, a branch or SHA).
--repository string The repository URL to import services from.
--username string The username to use when authenticating with HTTP or HTTPS.
--validate Validate the service file without importing.

Options inherited from parent commands

--profile string Specify the client profile to use (case-insensitive, defaults to [client] section)
--config string Path to the configuration file
--raw Display the result of the command in raw format
--verbose Enable verbose output