Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
138 changes: 138 additions & 0 deletions docs/migration-guide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
# Migrating from foreman-installer to foremanctl
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given the title and focus of the doc, I think the filename could use an update to reflect this.


## Overview

When upgrading from foreman-installer to foremanctl, the `foremanctl migrate` command helps convert your existing configuration to the new format.
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think it would be good to have steps here to install foremanctl on foreman-installer based setups?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure about it, but my thinking is installation steps are probably better suited for the main README or deployment docs rather than the migration guide docs or can add a simple "prerequisites" section with a link to installation docs. WDYT?

@ehelms @evgeni thoughts?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think since this guide is about how to upgrade from foreman-installer to foremanctl, that it should cover those steps for now. Like, prerequisites (e.g. foreman-installer installed, foremanctl present on the system) then run the steps. Or point to docs and say what steps should be run.


This guide explains how to migrate your foreman-installer answer files to foremanctl configuration files.

## Prerequisites

Before migrating, ensure the following:

1. **Foreman deployment using foreman-installer** - You should have an existing Foreman deployment has been installed using foreman-installer and has an answers file to migrate from.

2. **foremanctl is installed** on the system:
```bash
# Enable the foremanctl repository
dnf copr enable @theforeman/foremanctl rhel-9-x86_64

# Install foremanctl
dnf install foremanctl
```

For more installation options, see the main [README](../README.md#packages).

## Migration Workflow

1. **Generate the migrated configuration**:
```bash
foremanctl migrate --output /var/lib/foremanctl/parameters.yaml
```

2. **Review the output** for any warnings about unmapped parameters

3. **Use the migrated configuration** with foremanctl:
```bash
foremanctl deploy
```
(foremanctl automatically loads configuration from `/var/lib/foremanctl/parameters.yaml`)

## Command Usage

### Basic Migration

Migrate from the default location (reads the currently active scenario):
```bash
foremanctl migrate --output /var/lib/foremanctl/parameters.yaml
```

### Custom Answer File

Migrate from a specific answer file:
```bash
foremanctl migrate --answer-file /path/to/custom-answers.yaml --output /var/lib/foremanctl/parameters.yaml
```

### Output to stdout

Preview the migrated configuration without writing a file:
```bash
foremanctl migrate
```

## Command Options

- `--answer-file PATH` - Path to the foreman-installer answer file. If not specified, reads the currently active scenario and extracts the answer file path from it.
- `--output PATH` - Path for the migrated configuration (default: stdout)

> [!NOTE]
> Unlike other `foremanctl` commands, migrate does not persist parameters between runs. Each migration is independent.

## Parameter Mappings
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have an overlap now with parameters.md. I think either combine these two, or link out and capture this information in there.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i've linked it, looks better?


The migrate command automatically maps foreman-installer parameters to foremanctl parameters. For a complete list of all parameter mappings, see the [Parameters documentation](parameters.md#mapping).

## Example

Below is an example showing how the transformation works:

### Input (foreman-installer format)

```yaml
foreman:
db_host: database.example.com
db_port: 5432
db_database: foreman
db_username: foreman_user
db_password: secret123
db_manage: true
initial_admin_username: admin
initial_admin_password: changeme
```

### Output (foremanctl format)

```yaml
database_host: database.example.com
database_port: 5432
database_mode: external
foreman_database_name: foreman
foreman_database_password: secret123
foreman_database_user: foreman_user
foreman_initial_admin_password: changeme
foreman_initial_admin_username: admin
```

## Handling Unmapped Parameters

When the migration completes, you may see warnings like:

> [!WARNING]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is going to be tricky in practice. Users will need guidance on parameters that could not be mapped. Perhaps for now we can include as part of the warning output the high-level possible reasons they could not be mapped?

For example:

  1. There was an error trying to map it
  2. The value has no equivalent parameter / is unsupported
  3. other reasons?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's something that we'll have to learn (and document) as we go.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that is something we can focus on follow up work as well. Thanks for pointing it out.

> The following parameters could not be mapped:
> - katello::enable_ostree
> - foreman::some_other_param

These parameters need to be manually reviewed and added to the new configuration if needed. Check the [parameters documentation](parameters.md) for equivalent foremanctl parameters.
Comment thread
evgeni marked this conversation as resolved.

## Using the Migrated Configuration

Once you've generated and reviewed the migrated configuration:

1. **Save it to the foremanctl parameters file**:
```bash
# Either generate directly to the parameters file
foremanctl migrate --output /var/lib/foremanctl/parameters.yaml

# Or copy after review
foremanctl migrate --output /tmp/migrated.yaml
# Review /tmp/migrated.yaml
cp /tmp/migrated.yaml /var/lib/foremanctl/parameters.yaml
```

2. **Deploy using foremanctl**:
```bash
foremanctl deploy
```

The `foremanctl deploy` command automatically loads configuration from `/var/lib/foremanctl/parameters.yaml`.
1 change: 1 addition & 0 deletions src/ansible.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[defaults]
host_key_checking = False
roles_path = ./roles
library = ./plugins/modules
filter_plugins = ./filter_plugins
callback_plugins = ./callback_plugins
callback_result_format = yaml
Expand Down
15 changes: 15 additions & 0 deletions src/playbooks/migrate/metadata.obsah.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
help: |
Migrate foreman-installer answer file to foremanctl configuration format.

This command reads foreman-installer answer files and converts them to the
new foremanctl configuration format. Unmappable parameters are reported
as warnings but do not cause the command to fail.

variables:
answer_file:
Comment thread
evgeni marked this conversation as resolved.
help: Path to the foreman-installer answer file to migrate. If not specified, attempts to read from the default location.
persist: false
output:
help: Path where the migrated configuration should be written. If not specified, outputs to stdout.
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If not specified, it outputs to stdout currently, so just a thought should we also put those into default config /var/lib/foremanctl/parameters.yaml as well?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kept stdout as the default for the safer side, so that users can review output before it overwrites existing config. However, I believe we could document the recommended command: foremanctl migrate --output /var/lib/foremanctl/parameters.yaml. What's your preference?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That logic makes sense to me.

persist: false
29 changes: 29 additions & 0 deletions src/playbooks/migrate/migrate.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
- name: Migrate foreman-installer answer file to foremanctl format
hosts:
- quadlet
gather_facts: false
tasks:
- name: Run migration
migrate_answers:
answer_file: "{{ answer_file | default(omit) }}"
output: "{{ output | default(omit) }}"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if I pass --output diff.yaml , where file doesn't exist previously, and the file gets created under /usr/share/foremanctl/src/playbooks/migrate/diff.yaml instead of present working directory, is this expected?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no it was not expected, i see a bug now, let me fix that and address other comments as well

working_directory: "{{ lookup('env', 'PWD') }}"
register: migration_result

- name: Display migrated configuration to stdout
when: migration_result.output_content | default('') != ''
ansible.builtin.debug:
msg: "{{ migration_result.output_content }}"

- name: Display migration results
ansible.builtin.debug:
msg:
- "Migration completed successfully!"
- "Mapped parameters: {{ migration_result.mapped_count }}"
- "Unmappable parameters: {{ migration_result.unmappable_count }}"
- "{{ _unmappable_warning if migration_result.unmappable | length > 0 else '' }}"
- "{{ _output_file_msg if migration_result.output_file is defined else '' }}"
vars:
_unmappable_warning: "Warning: {{ migration_result.unmappable | length }} parameter(s) could not be mapped - see warnings above"
_output_file_msg: "Output written to: {{ migration_result.output_file }}"
Loading