### Setup Development Environment Source: https://docs.infrahub.app/sync/development Commands to clone the repository, install the uv package manager, and synchronize project dependencies. ```bash git clone https://github.com/opsmill/infrahub-sync.git cd infrahub-sync curl -LsSf https://astral.sh/uv/install.sh | sh uv sync --group dev ``` -------------------------------- ### Local Development Setup with uv Source: https://docs.infrahub.app/emma/getting-started/installation Instructions for installing dependencies and running the Emma application locally using the uv package manager and Streamlit. ```shell git clone https://github.com/opsmill/emma.git cd emma uv sync uv run streamlit run main.py ``` -------------------------------- ### Initialize Development Environment Source: https://docs.infrahub.app/bundle-dc/developer-guide Steps to clone the repository, install dependencies, start the Infrahub service, and bootstrap the initial data. ```bash # Clone repository git clone https://github.com/opsmill/infrahub-bundle-dc.git cd infrahub-bundle-dc # Install dependencies uv sync # Start Infrahub uv run invoke start # Optional: Enable Service Catalog in .env echo "INFRAHUB_SERVICE_CATALOG=true" >> .env uv run invoke restart # Load bootstrap data uv run invoke bootstrap ``` -------------------------------- ### Start Infrahub using Invoke Source: https://docs.infrahub.app/guides/installation Starts and initializes Infrahub for local development using the 'invoke' command-line tool. This command is typically run after cloning the repository and installing dependencies. ```bash uv run invoke demo.start ``` -------------------------------- ### Install Example Slurp'it Schema for Infrahub Source: https://docs.infrahub.app/sync/adapters/slurpit This code snippet demonstrates how to install the example Slurp'it schema into Infrahub. It involves creating a directory, downloading the schema file using curl, and then loading it into Infrahub using the infrahubctl command-line tool. ```bash mkdir slurpit-sync cd slurpit-sync curl -o schema.yml https://raw.githubusercontent.com/opsmill/infrahub/refs/heads/stable/models/examples/slurpit/slurpit.yml infrahubctl schema load schema.yml ``` -------------------------------- ### Install NetBox example schema Source: https://docs.infrahub.app/sync/adapters/netbox Commands to create a directory, download the example NetBox schema from the Infrahub repository, and load it into the Infrahub instance using infrahubctl. ```bash mkdir netbox-sync cd netbox-sync curl -o schema.yml https://raw.githubusercontent.com/opsmill/infrahub/refs/heads/stable/models/examples/netbox/netbox.yml infrahubctl schema load schema.yml ``` -------------------------------- ### Quick Start Deployment with Docker Compose Source: https://docs.infrahub.app/emma/getting-started/installation Downloads and executes the Infrahub and Emma configuration using a single curl command piped to Docker Compose. This method automatically sets up the necessary networking and services. ```shell curl https://infrahub.opsmill.io/1.6.2-emma | docker compose -f - up -d ``` -------------------------------- ### Install Python dependencies Source: https://docs.infrahub.app/bundle-dc/install Uses 'uv' to synchronize the project environment, creating a virtual environment and installing all necessary Python packages defined in the project. ```bash uv sync ``` -------------------------------- ### Configure environment variables Source: https://docs.infrahub.app/bundle-dc/install Initializes the project environment configuration by copying the example file and defining core Infrahub API, versioning, and service catalog settings. ```bash cp .env.example .env ``` ```ini INFRAHUB_ADDRESS=http://localhost:8000 INFRAHUB_API_TOKEN=06438eb2-8019-4776-878c-0941b1f1d1ec INFRAHUB_UI_URL=http://localhost:8000 INFRAHUB_VERSION=1.5.1 INFRAHUB_ENTERPRISE=false INFRAHUB_SERVICE_CATALOG=false DEFAULT_BRANCH=main GENERATOR_WAIT_TIME=60 API_TIMEOUT=30 API_RETRY_COUNT=3 ``` -------------------------------- ### Install Peering Manager Example Schema for Infrahub (Bash) Source: https://docs.infrahub.app/sync/adapters/peering-manager This script downloads the base schema and Peering Manager extension from GitHub, then loads them into Infrahub using the `infrahubctl` command. It requires `curl` and `jq` to be installed. ```bash mkdir peeringmanager-sync cd peeringmanager-sync # Fetch the list of YAML file names from the peeringmanager folder curl -s "https://api.github.com/repos/opsmill/infrahub/contents/models/base?ref=stable" | jq -r '.[].name | select(endswith(".yml"))' | while read file; do curl -O "https://raw.githubusercontent.com/opsmill/infrahub/refs/heads/stable/models/base/$file" done curl -O "https://raw.githubusercontent.com/opsmill/infrahub/refs/heads/stable/models/examples/extension_peering_manager.yml" infrahubctl schema load *.yml ``` -------------------------------- ### Install Infrahub using Ansible Playbooks Source: https://docs.infrahub.app/ansible/references/roles/install Examples for deploying Infrahub using the opsmill.infrahub.install role. Includes a minimal configuration for quick starts and an advanced configuration for production environments with custom variables. ```yaml - name: Install Infrahub hosts: infrahub_servers become: true roles: - role: opsmill.infrahub.install vars: install_infrahub_version: "latest" ``` ```yaml - name: Install Infrahub with custom configuration hosts: infrahub_servers become: true roles: - role: opsmill.infrahub.install vars: install_infrahub_version: "2.0.0" install_infrahub_install_directory: "/usr/local/infrahub" install_infrahub_docker_project: "infrahub_prod" install_infrahub_docker_pull_images: true install_infrahub_setup_systemd: true install_infrahub_systemd_service_state: "started" infrahub_config: INFRAHUB_ADMIN_EMAIL: "admin@example.com" INFRAHUB_ADMIN_PASSWORD: "secure_password" INFRAHUB_DATABASE_URL: "postgresql://user:pass@db:5432/infrahub" ``` -------------------------------- ### Clone and Build Emma Repository Source: https://docs.infrahub.app/emma/getting-started/installation Commands to clone the Emma source code from GitHub and build the containerized environment. ```shell git clone https://github.com/opsmill/emma.git cd emma docker compose up --build -d ``` -------------------------------- ### Clone Infrahub repository Source: https://docs.infrahub.app/bundle-dc/install Downloads the Infrahub demo bundle repository from GitHub to the local machine and navigates into the project directory. ```bash git clone https://github.com/opsmill/infrahub-bundle-dc.git cd infrahub-bundle-dc ``` -------------------------------- ### Verify uv installation Source: https://docs.infrahub.app/bundle-dc/install Checks the installed version of the 'uv' package manager to ensure it is correctly configured in the system path. ```bash uv --version ``` -------------------------------- ### Start Infrahub Containers with Invoke Source: https://docs.infrahub.app/bundle-dc/install This command starts all necessary Infrahub Docker containers using the invoke task runner. The first execution may take time due to Docker image downloads. ```shell uv run invoke start ``` -------------------------------- ### AI Prompt for Writing New Documentation Source: https://docs.infrahub.app/development/docs An example prompt for using AI to write new documentation. It specifies the topic, references existing files, provides a description of the feature, and requests examples for specific formats like GraphQL and CLI. ```plaintext Write a new documentation guide about [feature]. You can find the existing topic in [topic file]. The feature works like this: [description]. Make sure to include examples for [graphql, cli, etc.]. ``` -------------------------------- ### Start Infrahub Environment with Docker Compose (Linux) Source: https://docs.infrahub.app/guides/installation Starts the Infrahub environment using Docker Compose on Linux. It first downloads the docker-compose.yml file from infrahub.opsmill.io and then starts the containers in detached mode. ```bash curl https://infrahub.opsmill.io > docker-compose.yml sudo docker compose -p infrahub up -d ``` -------------------------------- ### Start Infrahub Enterprise environment with Docker Compose Source: https://docs.infrahub.app/guides/installation Downloads the Docker Compose configuration and initializes the Infrahub environment. Requires Docker 24.x or higher. ```bash curl https://infrahub.opsmill.io/enterprise > docker-compose.yml docker compose -p infrahub up -d ``` ```bash curl https://infrahub.opsmill.io/enterprise > docker-compose.yml sudo docker compose -p infrahub up -d ``` -------------------------------- ### Hello World Example (Sync) Source: https://docs.infrahub.app/python-sdk/guides/client A simple synchronous example to verify Infrahub client configuration. It connects to the Infrahub instance and queries for available accounts, printing a success or error message. ```python from infrahub_sdk import Config, InfrahubClientSync # Test connection and authentication def hello_world(): client = InfrahubClientSync(config=Config(address="http://localhost:8000")) # Try to query accounts to validate connection try: accounts = client.all(kind="CoreAccount") print(f"Successfully connected to Infrahub! Found {len(accounts)} account(s)") except Exception as e: print(f"Something went wrong: {e}") hello_world() ``` -------------------------------- ### Hello World Example (Async) Source: https://docs.infrahub.app/python-sdk/guides/client A simple asynchronous example to verify Infrahub client configuration. It connects to the Infrahub instance and queries for available accounts, printing a success or error message. ```python import asyncio from infrahub_sdk import Config, InfrahubClient async def hello_world(): client = InfrahubClient(config=Config(address="http://localhost:8000")) # Try to query accounts to validate connection try: accounts = await client.all(kind="CoreAccount") print(f"Successfully connected to Infrahub! Found {len(accounts)} account(s)") except Exception as e: print(f"Something went wrong: {e}") asyncio.run(hello_world()) ``` -------------------------------- ### Local Adapter Configuration Example (YAML) Source: https://docs.infrahub.app/sync/adapters/local-adapters Shows a sample YAML configuration for setting up a local adapter named `custom-example`. It specifies the source adapter's path and settings, the destination adapter, and the order of processing for schema mappings. ```yaml name: custom-example source: name: mockdb # Filesystem path to the adapter class adapter: ./examples/custom_adapter/custom_adapter_src/custom_adapter.py:MockdbAdapter settings: db_path: "./examples/custom_adapter/custom_adapter_src/mock_db.json" destination: name: infrahub settings: url: "http://localhost:8000" order: [ "InfraDevice", ] schema_mapping: # Your schema mapping here ``` -------------------------------- ### Download NetBox sync configuration Source: https://docs.infrahub.app/sync/adapters/netbox Command to download the example configuration file required for the NetBox to Infrahub synchronization process. ```bash curl https://raw.githubusercontent.com/opsmill/infrahub-sync/refs/heads/main/examples/netbox_to_infrahub/config.yml > config.yml ``` -------------------------------- ### InfraHub SDK for Repository Management Source: https://docs.infrahub.app/guides/repository Python SDK examples for creating credentials and repositories (both regular and read-only). ```APIDOC ## InfraHub SDK for Repository Management ### Description Programmatically manage Git repositories using the InfraHub SDK. This includes creating password credentials and then using them to instantiate `CoreRepository` or `CoreReadOnlyRepository` objects. ### Method InfraHub SDK (Python) ### Endpoint N/A (SDK methods) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body ##### Class: `CorePasswordCredential` * **name** (string) - Required - The name for the credential. * **username** (string) - Required - The username for Git authentication. * **password** (string) - Required - The password or token for Git authentication. ##### Class: `CoreRepository` * **name** (string) - Required - The name of the repository. * **location** (string) - Required - The URL of the Git repository. * **credential** (object) - Optional - The `CorePasswordCredential` object to use for authentication. ##### Class: `CoreReadOnlyRepository` * **name** (string) - Required - The name of the read-only repository. * **location** (string) - Required - The URL of the Git repository. * **ref** (string) - Required - The branch, tag, or commit to track. * **credential** (object) - Optional - The `CorePasswordCredential` object to use for authentication. ### Request Example ```python # Assuming 'client' is an authenticated InfraHub client instance # Create credential object credential = client.create( "CorePasswordCredential", name="My Git Credential", username="MY_USERNAME", password="MY_TOKEN_OR_PASSWORD", ) credential.save() # Create repository object repository = client.create( "CoreRepository", name="My Git repository", location="https://GIT_SERVER/YOUR_GIT_USERNAME/YOUR_REPOSITORY_NAME.git", credential=credential, # The credential object created above ) repository.save() ``` ```python # Assuming 'client' is an authenticated InfraHub client instance # Create credential object (optional, can reuse existing) credential = client.create( "CorePasswordCredential", name="My Git Credential", username="MY_USERNAME", password="MY_TOKEN_OR_PASSWORD", ) credential.save() # Create read-only repository object repository = client.create( "CoreReadOnlyRepository", name="My Git repository", location="https://GIT_SERVER/YOUR_GIT_USERNAME/YOUR_REPOSITORY_NAME.git", ref="BRANCH/TAG/COMMIT_TO_TRACK", credential=credential, # Optional: use the credential created above ) repository.save() ``` ### Response #### Success Response Objects are created and saved successfully. No explicit return value indicating success, but subsequent calls to list repositories should show the new entry. #### Response Example (No direct response example, as this is SDK method execution) ``` -------------------------------- ### Install uv package manager Source: https://docs.infrahub.app/bundle-dc/install Installs the 'uv' Python package manager on macOS, Linux, or Windows systems. This tool is required for managing project dependencies and virtual environments. ```bash # macOS and Linux curl -LsSf https://astral.sh/uv/install.sh | sh ``` ```powershell # Windows (PowerShell) powershell -c "irm https://astral.sh/uv/install.ps1 | iex" ``` -------------------------------- ### Start Infrahub Environment with Docker Compose (macOS) Source: https://docs.infrahub.app/guides/installation Starts the Infrahub environment using Docker Compose on macOS. It first downloads the docker-compose.yml file from infrahub.opsmill.io and then starts the containers in detached mode. ```bash curl https://infrahub.opsmill.io > docker-compose.yml docker compose -p infrahub up -d ``` -------------------------------- ### Download Example Slurp'it Configuration for Infrahub Source: https://docs.infrahub.app/sync/adapters/slurpit This command downloads the example configuration file (config.yml) for synchronizing data from Slurp'it to Infrahub. It uses curl to fetch the file from a GitHub repository and saves it locally. ```bash curl https://raw.githubusercontent.com/opsmill/infrahub-sync/refs/heads/main/examples/slurpit_to_infrahub/config.yml > config.yml ``` -------------------------------- ### POST /repository/init Source: https://docs.infrahub.app/infrahubctl/infrahubctl-repository Initializes a new Infrahub repository in the current environment. ```APIDOC ## POST infrahubctl repository init ### Description Initialize a new Infrahub repository structure. ### Method POST ### Endpoint infrahubctl repository init ### Request Example infrahubctl repository init ### Response #### Success Response (0) - **status** (string) - Repository initialized successfully. ``` -------------------------------- ### Configure direnv for Environment Variables Source: https://docs.infrahub.app/bundle-dc/install This snippet shows how to configure direnv to automatically load environment variables from a .envrc file when entering a project directory. It requires the direnv tool to be installed. ```shell dotenv direnv allow ``` -------------------------------- ### Infrahub Backup Create Command Examples Source: https://docs.infrahub.app/backup/reference/commands Illustrates various ways to use the 'create' command for backups. This includes basic creation, forcing backups, excluding metadata, uploading to S3, and retaining local files. ```bash # Basic backup infrahub-backup create # Force backup with running tasks infrahub-backup create --force # Backup without user metadata infrahub-backup create --neo4jmetadata=none # Backup and upload to S3 infrahub-backup create --s3-upload --s3-bucket my-backups --s3-prefix infrahub/prod # Backup and upload to S3, keeping local copy infrahub-backup create --s3-upload --s3-bucket my-backups --s3-keep-local ``` -------------------------------- ### Rebuild Infrahub Demo Instance Source: https://docs.infrahub.app/release-notes/infrahub/release-1_5_0 Commands to perform a clean installation of the demo environment. This will destroy existing data and re-initialize the instance with the latest schema and data. ```bash git fetch origin git checkout infrahub-v1.5.0 invoke demo.destroy demo.build demo.start demo.load-infra-schema demo.load-infra-data ``` -------------------------------- ### Validate CLI Functionality Source: https://docs.infrahub.app/sync/development Commands to verify the CLI installation and test core functionality like listing and generating configurations. ```bash uv run infrahub-sync --help uv run infrahub-sync list --directory examples/ uv run infrahub-sync generate --name from-netbox --directory examples/ ``` -------------------------------- ### Initialize Git Repository Source: https://docs.infrahub.app/guides/jinja2-transform Standard Git commands to initialize a new repository and commit the transformation files. ```bash git init --initial-branch=main git add . git commit -m "First commit" ``` -------------------------------- ### Create Directory (Shell) Source: https://docs.infrahub.app/vscode/tutorials/getting-started A simple shell command to create a new directory named 'schemas' in the current project root. ```shell mkdir schemas ``` -------------------------------- ### Connect Emma to Existing Infrahub Network Source: https://docs.infrahub.app/emma/getting-started/installation Steps to identify the active Infrahub Docker network and attach the Emma container to it to enable communication between services. ```shell docker network ls docker network connect emma-emma-1 ``` -------------------------------- ### Rule-Based Profile Application (Pseudocode) Source: https://docs.infrahub.app/topics/profiles Shows an example of dynamic assignment using rules, where Profiles are applied based on specific conditions. This enables automated and context-aware configuration management. ```pseudocode if: node.location == "datacenter-1" then: apply_profile("dc1-standards") ``` -------------------------------- ### Run Infrahub MCP Server Source: https://docs.infrahub.app/mcp/guides/installation Starts the Infrahub MCP server using 'uv run fastmcp run'. This command executes the main server script. ```bash uv run fastmcp run src/infrahub_mcp/server.py:mcp ``` -------------------------------- ### Manage Infrahub Demo Environment via Invoke Source: https://docs.infrahub.app/release-notes/infrahub/release-1_0_8 Uses Invoke tasks to stop, build, migrate, and start a demo instance. Includes a destructive command to reset the environment to a clean state. ```bash invoke demo.stop invoke demo.build invoke demo.migrate invoke demo.start # Destructive reset command invoke demo.destroy demo.build demo.start demo.load-infra-schema demo.load-infra-data ``` -------------------------------- ### Create Infrahub backups using CLI Source: https://docs.infrahub.app/backup/guides/backup-instance Commands to initiate backups with various options including forcing execution, filtering Neo4j metadata, specifying directories, and targeting specific projects. ```bash # Standard backup infrahub-backup create # Force backup (ignores running tasks) infrahub-backup create --force # Backup without metadata infrahub-backup create --neo4jmetadata=none # Backup with only user accounts infrahub-backup create --neo4jmetadata=users # Backup with only roles infrahub-backup create --neo4jmetadata=roles # Backup with everything infrahub-backup create --neo4jmetadata=all # Custom backup location infrahub-backup create --backup-dir=/mnt/backups/infrahub # Target specific project infrahub-backup create --project=infrahub-production ``` -------------------------------- ### Deploy Infrahub with Terraform Source: https://docs.infrahub.app/guides/installation Example Terraform configuration for deploying Infrahub to a Kubernetes cluster. It defines the necessary providers including Helm, Kubernetes, and Kubectl. ```hcl terraform { required_providers { kubectl = { source = "alekc/kubectl" version = "2.1.3" } } } provider "helm" { kubernetes = { config_path = "~/.kube/config" } } provider "kubernetes" { config_path = "~/.kube/config" } provider "kubectl" { config_path = "~/.kube/config" } locals { target_namespace = "infrahub" infrahub_version = "1.7.0" } ``` -------------------------------- ### Migrate InfraHub Demo Instance Source: https://docs.infrahub.app/release-notes/infrahub/release-1_1_5 Commands to stop, build, migrate, and start a demo instance of InfraHub. These commands are essential for updating the application to the latest version. ```shell invoke demo.stop invoke demo.buildinvoke demo.migrate invoke demo.start ``` -------------------------------- ### Manually Load Infrahub Schemas Source: https://docs.infrahub.app/bundle-dc/install This command manually loads the schema definitions for Infrahub. It is one of the steps involved in the manual bootstrap process. ```shell uv run infrahubctl schema load schemas ``` -------------------------------- ### Access Infrahub Web Interface Source: https://docs.infrahub.app/bundle-dc/install This URL is used to access the Infrahub web interface in a browser. Default credentials are provided for initial login. ```url http://localhost:8000 ``` -------------------------------- ### Batch Object Creation in Python Source: https://docs.infrahub.app/bundle-dc/concepts Demonstrates how to efficiently create multiple objects using batching with the Infrahub client. This reduces API calls and improves performance by grouping operations. ```python batch = await client.create_batch() for device in devices: batch.add(kind="DcimDevice", data=device) await batch.execute() ```