Sha256: d548cf2fa55fa107207c1fa45d0080e333a60b8b4ae3aab322d2c27e5e89c32c

Contents?: true

Size: 1.1 KB

Versions: 105

Compression:

Stored size: 1.1 KB

Contents

# frozen_string_literal: true

# Rename ansible job categories migration
class RenameAnsibleJobCategories < ActiveRecord::Migration[5.1]
  def up
    unless User.unscoped.find_by(:login => User::ANONYMOUS_ADMIN)
      STDOUT.puts 'No ANONYMOUS_ADMIN found. Skipping renaming Ansible jobs'
      return
    end
    User.as_anonymous_admin do
      updated_templates = ['Power Action - Ansible Default',
                           'Puppet Run Once - Ansible Default']
      JobTemplate.without_auditing do
        job_templates = JobTemplate.where(
          :name => updated_templates
        ).all
        job_templates.each do |job_template|
          next if job_template.job_category =~ /^Ansible/
          job_template.job_category = "Ansible #{job_template.job_category}"
          job_template.save
        end

        service_template = JobTemplate.where(
          :name => 'Service Action - Ansible Default'
        ).first
        if service_template.present?
          service_template.job_category = 'Ansible Services'
          service_template.save_without_auditing
        end
      end
    end
  end
end

Version data entries

105 entries across 105 versions & 1 rubygems

Version Path
foreman_ansible-15.0.3 db/migrate/20180410125416_rename_ansible_job_categories.rb
foreman_ansible-15.0.2 db/migrate/20180410125416_rename_ansible_job_categories.rb
foreman_ansible-15.0.1 db/migrate/20180410125416_rename_ansible_job_categories.rb
foreman_ansible-15.0.0 db/migrate/20180410125416_rename_ansible_job_categories.rb
foreman_ansible-14.2.2 db/migrate/20180410125416_rename_ansible_job_categories.rb
foreman_ansible-14.2.1 db/migrate/20180410125416_rename_ansible_job_categories.rb
foreman_ansible-13.0.7 db/migrate/20180410125416_rename_ansible_job_categories.rb
foreman_ansible-14.2.0 db/migrate/20180410125416_rename_ansible_job_categories.rb
foreman_ansible-14.1.1 db/migrate/20180410125416_rename_ansible_job_categories.rb
foreman_ansible-14.1.0 db/migrate/20180410125416_rename_ansible_job_categories.rb
foreman_ansible-13.0.5 db/migrate/20180410125416_rename_ansible_job_categories.rb
foreman_ansible-14.0.0 db/migrate/20180410125416_rename_ansible_job_categories.rb
foreman_ansible-13.0.4 db/migrate/20180410125416_rename_ansible_job_categories.rb
foreman_ansible-13.0.3 db/migrate/20180410125416_rename_ansible_job_categories.rb
foreman_ansible-13.0.2 db/migrate/20180410125416_rename_ansible_job_categories.rb
foreman_ansible-13.0.1 db/migrate/20180410125416_rename_ansible_job_categories.rb
foreman_ansible-13.0.0 db/migrate/20180410125416_rename_ansible_job_categories.rb
foreman_ansible-12.0.7 db/migrate/20180410125416_rename_ansible_job_categories.rb
foreman_ansible-10.4.4 db/migrate/20180410125416_rename_ansible_job_categories.rb
foreman_ansible-7.1.8 db/migrate/20180410125416_rename_ansible_job_categories.rb