Sha256: 9bfd361af75bc73d286306d10198033eed69612b68c58946bee423e70500be71

Contents?: true

Size: 1.02 KB

Versions: 15

Compression:

Stored size: 1.02 KB

Contents

class RenameAnsibleJobCategories < ActiveRecord::Migration[5.1]
  def up
    unless User.unscoped.find_by_login(User::ANONYMOUS_ADMIN)
      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

15 entries across 15 versions & 1 rubygems

Version Path
foreman_ansible-2.2.14 db/migrate/20180410125416_rename_ansible_job_categories.rb
foreman_ansible-2.2.13 db/migrate/20180410125416_rename_ansible_job_categories.rb
foreman_ansible-2.2.12 db/migrate/20180410125416_rename_ansible_job_categories.rb
foreman_ansible-2.2.11 db/migrate/20180410125416_rename_ansible_job_categories.rb
foreman_ansible-2.2.10 db/migrate/20180410125416_rename_ansible_job_categories.rb
foreman_ansible-2.2.9 db/migrate/20180410125416_rename_ansible_job_categories.rb
foreman_ansible-2.2.8 db/migrate/20180410125416_rename_ansible_job_categories.rb
foreman_ansible-2.2.7 db/migrate/20180410125416_rename_ansible_job_categories.rb
foreman_ansible-2.2.6 db/migrate/20180410125416_rename_ansible_job_categories.rb
foreman_ansible-2.2.5 db/migrate/20180410125416_rename_ansible_job_categories.rb
foreman_ansible-2.2.4 db/migrate/20180410125416_rename_ansible_job_categories.rb
foreman_ansible-2.2.3 db/migrate/20180410125416_rename_ansible_job_categories.rb
foreman_ansible-2.2.2 db/migrate/20180410125416_rename_ansible_job_categories.rb
foreman_ansible-2.2.1 db/migrate/20180410125416_rename_ansible_job_categories.rb
foreman_ansible-2.2.0 db/migrate/20180410125416_rename_ansible_job_categories.rb