From 4f236c7dbff1038fa1bf96bad9c7cd458e163016 Mon Sep 17 00:00:00 2001 From: Jeremy Lenz Date: Tue, 23 Jan 2024 14:36:47 -0500 Subject: [PATCH] Fixes #37051 - Add job templates for Ansible 'by search query' (#10850) --- ...search_query_-_katello_ansible_default.erb | 24 ++++++++++++++ ...search_query_-_katello_ansible_default.erb | 28 ++++++++++++++++ ...search_query_-_katello_ansible_default.erb | 26 +++++++++++++++ ...search_query_-_katello_ansible_default.erb | 33 +++++++++++++++++++ 4 files changed, 111 insertions(+) create mode 100644 app/views/foreman/job_templates/install_errata_by_search_query_-_katello_ansible_default.erb create mode 100644 app/views/foreman/job_templates/install_packages_by_search_query_-_katello_ansible_default.erb create mode 100644 app/views/foreman/job_templates/remove_packages_by_search_query_-_katello_ansible_default.erb create mode 100644 app/views/foreman/job_templates/update_packages_by_search_query_-_katello_ansible_default.erb diff --git a/app/views/foreman/job_templates/install_errata_by_search_query_-_katello_ansible_default.erb b/app/views/foreman/job_templates/install_errata_by_search_query_-_katello_ansible_default.erb new file mode 100644 index 00000000000..34918d0cf46 --- /dev/null +++ b/app/views/foreman/job_templates/install_errata_by_search_query_-_katello_ansible_default.erb @@ -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 -%> diff --git a/app/views/foreman/job_templates/install_packages_by_search_query_-_katello_ansible_default.erb b/app/views/foreman/job_templates/install_packages_by_search_query_-_katello_ansible_default.erb new file mode 100644 index 00000000000..bbb91ae5c1d --- /dev/null +++ b/app/views/foreman/job_templates/install_packages_by_search_query_-_katello_ansible_default.erb @@ -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 -%> + diff --git a/app/views/foreman/job_templates/remove_packages_by_search_query_-_katello_ansible_default.erb b/app/views/foreman/job_templates/remove_packages_by_search_query_-_katello_ansible_default.erb new file mode 100644 index 00000000000..3e7c2491ca2 --- /dev/null +++ b/app/views/foreman/job_templates/remove_packages_by_search_query_-_katello_ansible_default.erb @@ -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 diff --git a/app/views/foreman/job_templates/update_packages_by_search_query_-_katello_ansible_default.erb b/app/views/foreman/job_templates/update_packages_by_search_query_-_katello_ansible_default.erb new file mode 100644 index 00000000000..d442776370d --- /dev/null +++ b/app/views/foreman/job_templates/update_packages_by_search_query_-_katello_ansible_default.erb @@ -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 -%>