<commit_before>module Baustelle
  module AMI
    class PackerTemplate
      def initialize(definition, ami:, region:, user: 'ubuntu', system: 'ubuntu')
        @definition = definition
        @ami = ami
        @region = region
        @user = user
        @system = system
      end

      def valid?
        @ami && @region && File.exists?(playbook_path)
      end

      def as_json
        {
          builders: [
            {
              type: "amazon-ebs",
              access_key: "",
              secret_key: "",
              region: "#{@region}",
              source_ami: "#{@ami}",
              instance_type: "m4.large",
              ssh_username: @user,
              ssh_pty: true,
              ami_name: "baustelle-#{@definition}-#{Time.now.strftime('%Y%m%d%H%M%S')}",
              ami_description: "Baustelle Image #{@definition}",
              tags: {
                "BaustelleImage" => @definition
              }
            }
          ],
          provisioners: [
            {
              type: "shell",
              inline: install_ansible(@system)
            },
            {
              type: "ansible-local",
              playbook_dir: "ami",
              playbook_file: playbook_path
            }
          ]
        }
      end

      private

      def install_ansible(system)
        case system
        when 'ubuntu'
          [
            "sudo apt-get install -y software-properties-common",
            "sudo apt-add-repository ppa:ansible/ansible",
            "sudo apt-get update",
            "sudo apt-get install -y ansible",
          ]
        when 'amazon'
          [

          ]
        else
          raise "Unsupported base system"
        end
      end

      def playbook_path
        "ami/#{@definition}.yml"
      end
    end
  end
end<commit_msg>update packer template to install ansible via pip on amzn linux as epel version doesn't work<commit_after>module Baustelle
  module AMI
    class PackerTemplate
      def initialize(definition, ami:, region:, user: 'ubuntu', system: 'ubuntu')
        @definition = definition
        @ami = ami
        @region = region
        @user = user
        @system = system
      end

      def valid?
        @ami && @region && File.exists?(playbook_path)
      end

      def as_json
        {
          builders: [
            {
              type: "amazon-ebs",
              access_key: "",
              secret_key: "",
              region: "#{@region}",
              source_ami: "#{@ami}",
              instance_type: "m4.large",
              ssh_username: @user,
              ssh_pty: true,
              ami_name: "baustelle-#{@definition}-#{Time.now.strftime('%Y%m%d%H%M%S')}",
              ami_description: "Baustelle Image #{@definition}",
              tags: {
                "BaustelleImage" => @definition
              }
            }
          ],
          provisioners: [
            {
              type: "shell",
              inline: install_ansible(@system)
            },
            {
              type: "ansible-local",
              playbook_dir: "ami",
              playbook_file: playbook_path
            }
          ]
        }
      end

      private

      def install_ansible(system)
        case system
        when 'ubuntu'
          [
            "sudo apt-get install -y software-properties-common",
            "sudo apt-add-repository ppa:ansible/ansible",
            "sudo apt-get update",
            "sudo apt-get install -y ansible",
          ]
        when 'amazon'
          [
            "sudo pip install ansible --upgrade",
          ]
        else
          raise "Unsupported base system"
        end
      end

      def playbook_path
        "ami/#{@definition}.yml"
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.10498409331919406, 'fraction_numerical': 0.0005302226935312832, 'mean_word_length': 1.2674278846153846, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1195594', 'n_tokens_mistral': 1073, 'n_tokens_neox': 1033, 'n_words': 235}