From e6ebd6cba50ec5e5e2f36f489779aad087c0f8cd Mon Sep 17 00:00:00 2001 From: "Eric D. Helms" Date: Tue, 6 Aug 2024 09:43:48 -0400 Subject: [PATCH] Add Capsule update playbook separate from upgrade --- .../capsule_update_-_ansible_default.erb | 73 +++++++++++++++++++ lib/foreman_ansible/remote_execution.rb | 6 ++ 2 files changed, 79 insertions(+) create mode 100644 app/views/foreman_ansible/job_templates/capsule_update_-_ansible_default.erb diff --git a/app/views/foreman_ansible/job_templates/capsule_update_-_ansible_default.erb b/app/views/foreman_ansible/job_templates/capsule_update_-_ansible_default.erb new file mode 100644 index 00000000..1aad1da0 --- /dev/null +++ b/app/views/foreman_ansible/job_templates/capsule_update_-_ansible_default.erb @@ -0,0 +1,73 @@ +<%# +name: Capsule Update Playbook +snippet: false +template_inputs: +- name: whitelist_options + required: false + input_type: user + advanced: false + value_type: plain + hidden_value: false +model: JobTemplate +job_category: Maintenance Operations +description_format: "%{template_name}" +provider_type: Ansible +kind: job_template +feature: ansible_run_capsule_update +%> + +--- +- hosts: all + tasks: +<% if plugin_present?('foreman_theme_satellite') -%> + - name: Gather the rpm package facts + package_facts: + manager: auto + + - name: Fail if the target server is a Satellite server + fail: + msg: "This playbook cannot be executed on a Satellite server. Use only on a Capsule server." + when: "'satellite' in ansible_facts.packages" + + - name: Install|Update satellite-maintain if not present + package: + name: rubygem-foreman_maintain + state: latest + + - block: + <%- whitelist_option = if input('whitelist_options').present? + "--whitelist=#{input('whitelist_options')}" + end -%> + - name: Update Capsule server using satellite-maintain + shell: satellite-maintain update run --assumeyes <%= whitelist_option %> + register: result + + - name: Re-Gather the rpm package facts after the update + package_facts: + manager: auto + + - name: satellite-maintain update return code is zero + debug: + msg: "Success! Capsule server update completed. Current version of Capsule server server is {{ ansible_facts.packages['satellite-capsule'][0]['version'] }}." + + rescue: + - name: Print satellite-maintain output + debug: + var: result + + - name: Grep top 10 Error messages from /var/log/foreman-installer/capsule.log + shell: grep '^\[ERROR' /var/log/foreman-installer/capsule.log | head -n10 + register: output_grep + + - name: Print grepped Error messages + debug: + var: output_grep.stdout_lines + + - name: satellite-maintain update return code is non-zero + fail: + msg: "Failed! Capsule server update failed. See /var/log/foreman-installer/capsule.log in the Capsule server for more information" +<% else -%> + - name: Fail if foreman_theme_satellite is missing + fail: + msg: "Failed! The plugin foreman_theme_satellite is not present. This playbook is only for use with Satellite." +<% end -%> diff --git a/lib/foreman_ansible/remote_execution.rb b/lib/foreman_ansible/remote_execution.rb index 1474731d..e3ab405f 100644 --- a/lib/foreman_ansible/remote_execution.rb +++ b/lib/foreman_ansible/remote_execution.rb @@ -40,6 +40,12 @@ def self.register_rex_feature :description => N_('Upgrade Capsules on given Capsule server hosts'), :proxy_selector_override => ::RemoteExecutionProxySelector::INTERNAL_PROXY ) + RemoteExecutionFeature.register( + :ansible_run_capsule_update, + N_('Update Capsules on given hosts'), + :description => N_('Update Capsules on given Capsule server hosts'), + :proxy_selector_override => ::RemoteExecutionProxySelector::INTERNAL_PROXY + ) end end end