From 40e787d4c610ad53f3666ddb4212ff1d7d64dd97 Mon Sep 17 00:00:00 2001 From: Jeffrey Cutter Date: Wed, 9 Oct 2024 14:04:18 +0800 Subject: [PATCH] Update handling of local repositories for leapp_upgrade_type custom. Consolidate analysis and upgrade custom-local-repos.yml task files to infra.leapp.common custom_local_repos.yml. Use infra.leapp.common custom_local_repos.yml to generate all repository files. Ensure leapp_upgrade_repositories.repo only has content from the current run of local_repos_leapp variable. --- changelogs/fragments/custom_local_repos.yml | 5 +++ roles/analysis/tasks/analysis-leapp.yml | 36 +++++++++---------- roles/analysis/tasks/analysis-preupg.yml | 16 +++++---- .../tasks/custom_local_repos.yml} | 13 +++++-- roles/upgrade/tasks/custom-local-repos.yml | 18 ---------- roles/upgrade/tasks/leapp-post-upgrade.yml | 8 +++-- roles/upgrade/tasks/leapp-upgrade.yml | 27 ++++++-------- .../redhat-upgrade-tool-post-upgrade.yml | 8 +++-- .../tasks/redhat-upgrade-tool-upgrade.yml | 8 +++-- 9 files changed, 67 insertions(+), 72 deletions(-) create mode 100644 changelogs/fragments/custom_local_repos.yml rename roles/{analysis/tasks/custom-local-repos.yml => common/tasks/custom_local_repos.yml} (53%) delete mode 100644 roles/upgrade/tasks/custom-local-repos.yml diff --git a/changelogs/fragments/custom_local_repos.yml b/changelogs/fragments/custom_local_repos.yml new file mode 100644 index 0000000..8efcf54 --- /dev/null +++ b/changelogs/fragments/custom_local_repos.yml @@ -0,0 +1,5 @@ +--- +minor_changes: +- Consolidate analysis and upgrade custom-local-repos.yml task files to infra.leapp.common custom_local_repos.yml. +- Use infra.leapp.common custom_local_repos.yml to generate all repository files. +- Ensure leapp_upgrade_repositories.repo only has content from the current run of local_repos_leapp variable. \ No newline at end of file diff --git a/roles/analysis/tasks/analysis-leapp.yml b/roles/analysis/tasks/analysis-leapp.yml index a88b089..df1b181 100644 --- a/roles/analysis/tasks/analysis-leapp.yml +++ b/roles/analysis/tasks/analysis-leapp.yml @@ -11,10 +11,12 @@ - satellite_organization is defined - satellite_activation_key_leapp is defined -- name: analysis-leapp | Include custom-local-repos.yml for local_repos_pre_leapp +- name: analysis-leapp | Include custom_local_repos for local_repos_pre_leapp vars: - __local_repos: "{{ local_repos_pre_leapp }}" - ansible.builtin.include_tasks: custom-local-repos.yml + __repos: "{{ local_repos_pre_leapp }}" + ansible.builtin.include_role: + name: infra.leapp.common + tasks_from: custom_local_repos when: leapp_upgrade_type == "custom" - name: analysis-leapp | Install packages for preupgrade analysis on RHEL 7 @@ -48,20 +50,12 @@ when: leapp_answerfile is defined - name: analysis-leapp | Create /etc/leapp/files/leapp_upgrade_repositories.repo - ansible.builtin.yum_repository: - name: "{{ item.name }}" - description: "{{ item.description }}" - baseurl: "{{ item.baseurl }}" - enabled: "{{ item.enabled | default(1) }}" - gpgcheck: "{{ item.gpgcheck | default(0) }}" - gpgkey: "{{ item.gpgkey | default(omit) }}" - repo_gpgcheck: "{{ item.repo_gpgcheck | default(omit) }}" - file: /etc/leapp/files/leapp_upgrade_repositories - state: present - owner: root - group: root - mode: "0644" - loop: "{{ local_repos_leapp }}" + vars: + __repos: "{{ local_repos_leapp }}" + __leapp_repo_file: /etc/leapp/files/leapp_upgrade_repositories + ansible.builtin.include_role: + name: infra.leapp.common + tasks_from: custom_local_repos when: - leapp_upgrade_type == 'custom' - local_repos_leapp | length > 0 @@ -83,10 +77,12 @@ poll: "{{ async_poll_interval | int }}" failed_when: "'report has been generated' not in leapp.stdout" -- name: analysis-leapp | Include custom-local-repos.yml for local_repos_post_analysis +- name: analysis-leapp | Include custom_local_repos for local_repos_post_analysis vars: - __local_repos: "{{ local_repos_post_analysis }}" - ansible.builtin.include_tasks: custom-local-repos.yml + __repos: "{{ local_repos_post_analysis }}" + ansible.builtin.include_role: + name: infra.leapp.common + tasks_from: custom_local_repos when: leapp_upgrade_type == "custom" - name: analysis-leapp | Include check-results-file.yml diff --git a/roles/analysis/tasks/analysis-preupg.yml b/roles/analysis/tasks/analysis-preupg.yml index 96d6f2a..124517b 100644 --- a/roles/analysis/tasks/analysis-preupg.yml +++ b/roles/analysis/tasks/analysis-preupg.yml @@ -16,10 +16,12 @@ failed_when: false changed_when: true -- name: analysis-preupg | Include custom-local-repos.yml for local_repos_pre_leapp +- name: analysis-preupg | Include custom_local_repos for local_repos_pre_leapp vars: - __local_repos: "{{ local_repos_pre_leapp }}" - ansible.builtin.include_tasks: custom-local-repos.yml + __repos: "{{ local_repos_pre_leapp }}" + ansible.builtin.include_role: + name: infra.leapp.common + tasks_from: custom_local_repos when: leapp_upgrade_type == "custom" - name: analysis-preupg | Enable requisite RHUI repos @@ -75,10 +77,12 @@ that: not preupg_return_codes[preupg.rc].fail msg: "{{ preupg_return_codes[preupg.rc].msg }}" -- name: analysis-preupg | Include custom-local-repos.yml for local_repos_post_analysis +- name: analysis-preupg | Include custom_local_repos for local_repos_post_analysis vars: - __local_repos: "{{ local_repos_post_analysis }}" - ansible.builtin.include_tasks: custom-local-repos.yml + __repos: "{{ local_repos_post_analysis }}" + ansible.builtin.include_role: + name: infra.leapp.common + tasks_from: custom_local_repos when: leapp_upgrade_type == "custom" - name: analysis-preupg | Include check-results-file.yml diff --git a/roles/analysis/tasks/custom-local-repos.yml b/roles/common/tasks/custom_local_repos.yml similarity index 53% rename from roles/analysis/tasks/custom-local-repos.yml rename to roles/common/tasks/custom_local_repos.yml index 67e374a..74abe1c 100644 --- a/roles/analysis/tasks/custom-local-repos.yml +++ b/roles/common/tasks/custom_local_repos.yml @@ -1,5 +1,12 @@ --- -- name: custom-local-repos | Enable custom upgrade yum repositories +- name: custom_local_repos | Remove old /etc/leapp/files/leapp_upgrade_repositories.repo + ansible.builtin.file: + path: /etc/leapp/files/leapp_upgrade_repositories.repo + state: absent + when: + - __leapp_repo_file is defined + +- name: custom_local_repos | Enable custom upgrade yum repositories ansible.builtin.yum_repository: name: "{{ item.name }}" description: "{{ item.description }}" @@ -8,11 +15,11 @@ gpgcheck: "{{ item.gpgcheck | default(0) }}" gpgkey: "{{ item.gpgkey | default(omit) }}" repo_gpgcheck: "{{ item.repo_gpgcheck | default(omit) }}" - file: "{{ item.file | default('local') }}" + file: "{{ __leapp_repo_file | default(item.file) | default('local') }}" state: "{{ item.state | default('present') }}" owner: root group: root mode: "0644" - loop: "{{ __local_repos }}" + loop: "{{ __repos }}" ... diff --git a/roles/upgrade/tasks/custom-local-repos.yml b/roles/upgrade/tasks/custom-local-repos.yml deleted file mode 100644 index 67e374a..0000000 --- a/roles/upgrade/tasks/custom-local-repos.yml +++ /dev/null @@ -1,18 +0,0 @@ ---- -- name: custom-local-repos | Enable custom upgrade yum repositories - ansible.builtin.yum_repository: - name: "{{ item.name }}" - description: "{{ item.description }}" - baseurl: "{{ item.baseurl }}" - enabled: "{{ item.enabled | default(1) }}" - gpgcheck: "{{ item.gpgcheck | default(0) }}" - gpgkey: "{{ item.gpgkey | default(omit) }}" - repo_gpgcheck: "{{ item.repo_gpgcheck | default(omit) }}" - file: "{{ item.file | default('local') }}" - state: "{{ item.state | default('present') }}" - owner: root - group: root - mode: "0644" - loop: "{{ __local_repos }}" - -... diff --git a/roles/upgrade/tasks/leapp-post-upgrade.yml b/roles/upgrade/tasks/leapp-post-upgrade.yml index 71d9121..1a805e0 100644 --- a/roles/upgrade/tasks/leapp-post-upgrade.yml +++ b/roles/upgrade/tasks/leapp-post-upgrade.yml @@ -92,10 +92,12 @@ - satellite_organization is defined - satellite_activation_key_post_leapp is defined -- name: leapp-post-upgrade | Include custom-local-repos.yml for local_repos_post_upgrade +- name: leapp-post-upgrade | Include custom_local_repos for local_repos_post_upgrade vars: - __local_repos: "{{ local_repos_post_upgrade }}" - ansible.builtin.include_tasks: custom-local-repos.yml + __repos: "{{ local_repos_post_upgrade }}" + ansible.builtin.include_role: + name: infra.leapp.common + tasks_from: custom_local_repos when: leapp_upgrade_type == "custom" - name: leapp-post-upgrade | Include update-and-reboot.yml diff --git a/roles/upgrade/tasks/leapp-upgrade.yml b/roles/upgrade/tasks/leapp-upgrade.yml index 212c1bf..ce60e28 100644 --- a/roles/upgrade/tasks/leapp-upgrade.yml +++ b/roles/upgrade/tasks/leapp-upgrade.yml @@ -21,29 +21,24 @@ - satellite_organization is defined - satellite_activation_key_leapp is defined -- name: leapp-upgrade | Include custom-local-repos.yml local_repos_pre_leapp +- name: leapp-upgrade | Include custom_local_repos for local_repos_pre_leapp vars: - __local_repos: "{{ local_repos_pre_leapp }}" - ansible.builtin.include_tasks: custom-local-repos.yml + __repos: "{{ local_repos_pre_leapp }}" + ansible.builtin.include_role: + name: infra.leapp.common + tasks_from: custom_local_repos when: leapp_upgrade_type == "custom" - name: leapp-upgrade | Include update-and-reboot.yml ansible.builtin.include_tasks: update-and-reboot.yml - name: leapp-upgrade | Create /etc/leapp/files/leapp_upgrade_repositories.repo - ansible.builtin.yum_repository: - name: "{{ item.name }}" - description: "{{ item.description }}" - baseurl: "{{ item.baseurl }}" - enabled: "{{ item.enabled | default(1) }}" - gpgcheck: "{{ item.gpgcheck | default(0) }}" - gpgkey: "{{ item.gpgkey | default(omit) }}" - repo_gpgcheck: "{{ item.repo_gpgcheck | default(omit) }}" - file: /etc/leapp/files/leapp_upgrade_repositories - owner: root - group: root - mode: "0644" - loop: "{{ local_repos_leapp }}" + vars: + __repos: "{{ local_repos_leapp }}" + __leapp_repo_file: /etc/leapp/files/leapp_upgrade_repositories + ansible.builtin.include_role: + name: infra.leapp.common + tasks_from: custom_local_repos when: - leapp_upgrade_type == 'custom' - local_repos_leapp | length > 0 diff --git a/roles/upgrade/tasks/redhat-upgrade-tool-post-upgrade.yml b/roles/upgrade/tasks/redhat-upgrade-tool-post-upgrade.yml index bcabfc6..e370518 100644 --- a/roles/upgrade/tasks/redhat-upgrade-tool-post-upgrade.yml +++ b/roles/upgrade/tasks/redhat-upgrade-tool-post-upgrade.yml @@ -20,10 +20,12 @@ failed_when: false changed_when: true -- name: redhat-upgrade-tool-post-upgrade | Include custom-local-repos.yml for local_repos_post_upgrade +- name: redhat-upgrade-tool-post-upgrade | Include custom_local_repos for local_repos_post_upgrade vars: - __local_repos: "{{ local_repos_post_upgrade }}" - ansible.builtin.include_tasks: custom-local-repos.yml + __repos: "{{ local_repos_post_upgrade }}" + ansible.builtin.include_role: + name: infra.leapp.common + tasks_from: custom_local_repos when: leapp_upgrade_type == "custom" - name: redhat-upgrade-tool-post-upgrade | Include check-for-old-packages.yml diff --git a/roles/upgrade/tasks/redhat-upgrade-tool-upgrade.yml b/roles/upgrade/tasks/redhat-upgrade-tool-upgrade.yml index 673959a..d87d237 100644 --- a/roles/upgrade/tasks/redhat-upgrade-tool-upgrade.yml +++ b/roles/upgrade/tasks/redhat-upgrade-tool-upgrade.yml @@ -31,10 +31,12 @@ failed_when: false changed_when: true -- name: redhat-upgrade-tool-upgrade | Include custom-local-repos.yml local_repos_post_upgrade +- name: redhat-upgrade-tool-upgrade | Include custom_local_repos for local_repos_post_upgrade vars: - __local_repos: "{{ local_repos_pre_leapp }}" - ansible.builtin.include_tasks: custom-local-repos.yml + __repos: "{{ local_repos_pre_leapp }}" + ansible.builtin.include_role: + name: infra.leapp.common + tasks_from: custom_local_repos when: leapp_upgrade_type == "custom" - name: redhat-upgrade-tool-upgrade | Gather package facts