Skip to content

Commit

Permalink
Fixes #37051 - Add job templates for Ansible 'by search query' (#10850)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremylenz authored Jan 23, 2024
1 parent f281fc5 commit 4f236c7
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<%#
kind: job_template
name: Install errata by search query - Katello Ansible Default
job_category: Katello
description_format: 'Install errata %{Errata search query}'
feature: katello_errata_install_by_search
provider_type: Ansible
template_inputs:
- name: Errata search query
description: Filter criteria for errata to be installed.
input_type: user
required: false
%>

<% advisory_ids = @host.advisory_ids(search: input("Errata search query")) -%>
<% render_error(N_("No errata matching given search query")) if !input("Errata search query").blank? && advisory_ids.blank? -%>
# RESOLVED_ERRATA_IDS=<%= advisory_ids.join(',') %>

<% if @host.operatingsystem.family == 'Suse' -%>
<%= render_template('Run Command - Ansible Default', :command => "zypper -n install -t patch #{advisory_ids.join(' ')}") %>
<% else -%>
<% advisories = advisory_ids.map { |e| "--advisory=#{e}" }.join(' ') -%>
<%= render_template('Run Command - Ansible Default', :command => "yum -y update-minimal #{advisories}") %>
<% end -%>
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<%#
kind: job_template
name: Install packages by search query - Katello Ansible Default
job_category: Katello
description_format: 'Install package(s) %{Package search query}'
feature: katello_package_install_by_search
provider_type: Ansible
template_inputs:
- name: Package search query
description: Filter criteria for packages to be installed. IMPORTANT- If left blank, the job will attempt to install all possible packages.
input_type: user
required: false
%>
<% package_names = @host.package_names_for_job_template(
action: 'install',
search: input('Package search query')
) -%>
---
- hosts: all
tasks:
- package:
<% if package_names.empty? -%>
name: []
<% else -%>
name: <%= indent(10) { to_yaml(package_names).gsub(/---/, "") } -%>
state: present
<% end -%>

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<%#
kind: job_template
name: Remove packages by search query - Katello Ansible Default
job_category: Katello
description_format: 'Remove package(s) %{Packages search query}'
feature: katello_package_remove_by_search
provider_type: Ansible
template_inputs:
- name: Packages search query
description: Filter criteria for packages to be removed.
input_type: user
required: false
%>
<% package_names = @host.package_names_for_job_template(
action: 'remove',
search: input('Packages search query')
) -%>
---
- hosts: all
tasks:
- package:
name:
<% package_names.each do |package_name| -%>
- <%= package_name %>
<% end -%>
state: absent
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<%#
kind: job_template
name: Update packages by search query - Katello Ansible Default
job_category: Katello
description_format: 'Update package(s) %{Packages search query}'
feature: katello_package_remove_by_search
provider_type: Ansible
template_inputs:
- name: Packages search query
description: Filter criteria for packages to be updated.
input_type: user
required: false
- name: Selected update versions
description: JSON string of selected package versions to be updated, in the format [ nvra ]. Leave blank to upgrade to latest available version.
input_type: user
required: false
value_type: plain
%>
<% package_names = @host.package_names_for_job_template(
action: 'update',
search: input('Packages search query'),
versions: input('Selected update versions')
) -%>
<% if package_names.empty? -%>
<%= render_template('Run Command - Ansible Default', :command => "yum -y update") %>
<% else -%>
---
- hosts: all
tasks:
- package:
name: <%= indent(10) { to_yaml(package_names).gsub(/---/, "") } -%>
state: latest
<% end -%>

0 comments on commit 4f236c7

Please sign in to comment.