Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update capsule upgrade #727

Merged
merged 2 commits into from
Aug 16, 2024
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
Original file line number Diff line number Diff line change
@@ -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 -%>
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ feature: ansible_run_capsule_upgrade

---
- hosts: all
vars:
target_version: "<%= input('target_version').present? ? input('target_version') : product_short_version %>"
tasks:
<% if plugin_present?('foreman_theme_satellite') -%>
- name: Gather the rpm package facts
Expand All @@ -47,7 +45,7 @@ feature: ansible_run_capsule_upgrade
"--whitelist=#{input('whitelist_options')}"
end -%>
- name: Upgrade Capsule server using satellite-maintain
shell: satellite-maintain upgrade run --assumeyes --target-version={{ target_version }} <%= whitelist_option %>
shell: satellite-maintain upgrade run --assumeyes <%= whitelist_option %>
adamruzicka marked this conversation as resolved.
Show resolved Hide resolved
register: result

- name: Re-Gather the rpm package facts after the upgrade
Expand Down
6 changes: 6 additions & 0 deletions lib/foreman_ansible/remote_execution.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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