Skip to content

Instantly share code, notes, and snippets.

@sjha4
Created June 25, 2026 18:27
Show Gist options
  • Select an option

  • Save sjha4/65e43e7ad8147b40d32ed02c7ba92710 to your computer and use it in GitHub Desktop.

Select an option

Save sjha4/65e43e7ad8147b40d32ed02c7ba92710 to your computer and use it in GitHub Desktop.
Restore changes to support proxy flavor
[root@ip-10-0-168-10 backup]# cat /tmp/backup/foreman-proxy-restore.patch
From: Claude Code
Date: Thu, 25 Jun 2026
Subject: [PATCH] Fix restore for foreman-proxy installations
Make foreman database restoration and deployment conditional based on
installation flavor to support foreman-proxy systems that don't have
the foreman database or full foreman services.
Changes:
1. Make foreman database restoration conditional on 'foreman' feature
2. Use deploy-proxy.yaml for foreman-proxy installations
3. Update verification to check appropriate services per flavor
---
src/playbooks/restore/restore.yaml | 39 ++++++++++++++++---
src/roles/restore/tasks/restore_databases.yaml | 1 +
2 files changed, 35 insertions(+), 5 deletions(-)
diff --git a/src/roles/restore/tasks/restore_databases.yaml b/src/roles/restore/tasks/restore_databases.yaml
index 14f8a92..a5c3e1f 100644
--- a/src/roles/restore/tasks/restore_databases.yaml
+++ b/src/roles/restore/tasks/restore_databases.yaml
@@ -37,6 +37,7 @@
- name: foreman
dump_file: "{{ foreman_database_name }}.dump"
database_name: "{{ foreman_database_name }}"
owner: "{{ foreman_database_user }}"
+ when_feature: foreman
- name: candlepin
dump_file: "{{ candlepin_database_name }}.dump"
database_name: "{{ candlepin_database_name }}"
diff --git a/src/playbooks/restore/restore.yaml b/src/playbooks/restore/restore.yaml
index 7c5f8a9..8d2e4c1 100644
--- a/src/playbooks/restore/restore.yaml
+++ b/src/playbooks/restore/restore.yaml
@@ -11,18 +11,47 @@
roles:
- restore
-- name: Deploy services after restore
+- name: Deploy services after restore (foreman-proxy)
+ import_playbook: ../deploy-proxy/deploy-proxy.yaml
+ when:
+ - not validate | default(false)
+ - flavor is match('foreman-proxy.*')
+
+- name: Deploy services after restore (foreman)
import_playbook: ../deploy/deploy.yaml
- when: not validate | default(false)
+ when:
+ - not validate | default(false)
+ - not (flavor is match('foreman-proxy.*'))
- name: Verify restore completion
- hosts: quadlet
+ hosts: "{{ 'proxy' if flavor is match('foreman-proxy.*') else 'quadlet' }}"
become: true
gather_facts: false
tasks:
- name: Verify services after restore
when: not validate | default(false)
block:
- name: Wait for services to stabilize
ansible.builtin.pause:
seconds: 30
- name: Check foreman.target status
ansible.builtin.systemd:
name: foreman.target
register: restore_target_status
failed_when: restore_target_status.status.ActiveState != 'active'
+ when: not (flavor is match('foreman-proxy.*'))
- name: Wait for Foreman API to respond
ansible.builtin.uri:
url: "https://{{ ansible_fqdn }}/api/status"
method: GET
validate_certs: false
status_code: [200, 401]
register: restore_api_check
until: restore_api_check.status in [200, 401]
retries: 30
delay: 10
changed_when: false
+ when: not (flavor is match('foreman-proxy.*'))
+
+ - name: Check foreman-proxy services
+ ansible.builtin.systemd:
+ name: "{{ item }}"
+ register: restore_proxy_status
+ failed_when: restore_proxy_status.status.ActiveState != 'active'
+ loop:
+ - foreman-proxy.service
+ - httpd.service
+ when: flavor is match('foreman-proxy.*')
--
2.45.2
@sjha4

sjha4 commented Jul 17, 2026

Copy link
Copy Markdown
Author
[root@ip-10-0-199-110 ~]# cat /tmp/restore-proxy-support.patch
diff --git a/src/playbooks/restore/metadata.obsah.yaml b/src/playbooks/restore/metadata.obsah.yaml
index 54c126e..6cd579f 100644
--- a/src/playbooks/restore/metadata.obsah.yaml
+++ b/src/playbooks/restore/metadata.obsah.yaml
@@ -17,6 +17,10 @@ variables:
     action: store_true
     persist: false
 
+  target_host:
+    help: Target host to restore (defaults to quadlet)
+    persist: false
+
   force:
     help: Force restore on existing system (bypasses safety check)
     action: store_true
diff --git a/src/playbooks/restore/restore.yaml b/src/playbooks/restore/restore.yaml
index b9fa881..e045644 100644
--- a/src/playbooks/restore/restore.yaml
+++ b/src/playbooks/restore/restore.yaml
@@ -1,6 +1,6 @@
 ---
 - name: Restore from a backup
-  hosts: quadlet
+  hosts: "{{ target_host | default('quadlet') }}"
   become: true
   gather_facts: true
   vars_files:
@@ -10,6 +10,89 @@
   roles:
     - restore
 
-- name: Deploy services after restore
+- name: Load restored parameters for deploy
+  hosts: "{{ target_host | default('quadlet') }}"
+  become: true
+  gather_facts: false
+  tasks:
+    - name: Read restored parameters
+      ansible.builtin.slurp:
+        path: "{{ obsah_state_path }}/parameters.yaml"
+      register: restore_params_raw
+      failed_when: false
+      when: not validate | default(false)
+
+    - name: Parse restored parameters
+      ansible.builtin.set_fact:
+        restore_params: "{{ restore_params_raw.content | b64decode | from_yaml }}"
+      when:
+        - not validate | default(false)
+        - restore_params_raw is succeeded
+
+    - name: Set restore flavor
+      ansible.builtin.set_fact:
+        restore_flavor: "{{ restore_params.flavor | default('katello') }}"
+      when: restore_params is defined
+
+    - name: Set proxy deploy parameters
+      ansible.builtin.set_fact:
+        foreman_name: "{{ restore_params.foreman_name }}"
+        foreman_proxy_oauth_consumer_key: "{{ restore_params.foreman_proxy_oauth_consumer_key }}"
+        foreman_proxy_oauth_consumer_secret: "{{ restore_params.foreman_proxy_oauth_consumer_secret }}"
+      when:
+        - restore_params is defined
+        - restore_flavor | default('') is match('foreman-proxy.*')
+
+- name: Deploy services after restore (foreman-proxy)
+  import_playbook: ../deploy-proxy/deploy-proxy.yaml
+  when:
+    - not validate | default(false)
+    - restore_flavor | default('') is match('foreman-proxy.*')
+
+- name: Deploy services after restore (server)
   import_playbook: ../deploy/deploy.yaml
-  when: not validate | default(false)
+  when:
+    - not validate | default(false)
+    - restore_flavor | default('') == 'katello'
+
+- name: Verify restore completion
+  hosts: "{{ target_host | default('quadlet') }}"
+  become: true
+  gather_facts: true
+  tasks:
+    - name: Verify services after restore
+      when: not validate | default(false)
+      block:
+        - name: Wait for services to stabilize
+          ansible.builtin.pause:
+            seconds: 30
+
+        - name: Check foreman.target status
+          ansible.builtin.systemd:
+            name: foreman.target
+          register: restore_target_status
+          failed_when: restore_target_status.status.ActiveState != 'active'
+          when: not (restore_flavor | default('') is match('foreman-proxy.*'))
+
+        - name: Wait for Foreman API to respond
+          ansible.builtin.uri:
+            url: "https://{{ ansible_fqdn }}/api/status"
+            method: GET
+            validate_certs: false
+            status_code: [200, 401]
+          register: restore_api_check
+          until: restore_api_check.status in [200, 401]
+          retries: 30
+          delay: 10
+          changed_when: false
+          when: not (restore_flavor | default('') is match('foreman-proxy.*'))
+
+        - name: Check foreman-proxy services
+          ansible.builtin.systemd:
+            name: "{{ item }}"
+          register: restore_proxy_status
+          failed_when: restore_proxy_status.status.ActiveState != 'active'
+          loop:
+            - foreman-proxy.service
+            - httpd.service
+          when: restore_flavor | default('') is match('foreman-proxy.*')
diff --git a/src/roles/restore/tasks/restore_databases.yaml b/src/roles/restore/tasks/restore_databases.yaml
index fda2c36..d43c279 100644
--- a/src/roles/restore/tasks/restore_databases.yaml
+++ b/src/roles/restore/tasks/restore_databases.yaml
@@ -27,7 +27,7 @@
       dump_file: "{{ restore_backup_metadata.database_mapping[item.name] }}.dump"
       database: "{{ item.database }}"
       user: "{{ item.user }}"
-  loop: "{{ databases }}"
+  loop: "{{ databases | selectattr('name', 'in', restore_backup_metadata.databases) | list }}"
   loop_control:
     label: "{{ item.name }}"
 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment