<commit_before>{
  "AWSTemplateFormatVersion" : "2010-09-09",

  "Description" : "Chef Server for SkyHopper",

  "Parameters" : {
    "KeyName" : {
      "Description" : "Name of an existing EC2 KeyPair to enable SSH access to the instance",
      "Type" : "String"
    },
    "InstanceType" : {
      "Description" : "WebServer EC2 instance type",
      "Type" : "String",
      "Default" : "t2.small",
      "AllowedValues": <%= fragment(:ec2_instance_types_hvm) %>,
      "ConstraintDescription" : "must be a valid EC2 instance type."
    },
    "SSHLocation" : {
      "Description" : "The IP address range that can be used to SSH to the EC2 instances",
      "Type": "String",
      "MinLength": "9",
      "MaxLength": "18",
      "Default": "0.0.0.0/0",
      "AllowedPattern": "(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})/(\\d{1,2})",
      "ConstraintDescription": "must be a valid IP CIDR range of the form x.x.x.x/x."
    },
    "InstanceName": {
      "Description" : "Name of EC2 Instance",
      "Type" : "String",
      "Default": "Chef Server for SkyHopper"
    },

    "ChefPackageURL": { "Type" : "String", "Default": "https://web-dl.packagecloud.io/chef/stable/packages/el/6/chef-server-core-12.0.8-1.el6.x86_64.rpm" },
    "ChefUser":       { "Type" : "String", "Default": "skyhopper" },
    "ChefFullName":   { "Type" : "String", "Default": "anakin skyhopper" },
    "ChefEmail":      { "Type" : "String", "Default": "<EMAIL>" },
    "ChefPassword":   { "Type" : "String", "Default": "<PASSWORD>" },
    "ChefOrg":        { "Type" : "String", "Default": "skyarch" },
    "ChefFullOrg":    { "Type" : "String", "Default": "Skyarch Networks Inc." },

    "UserPemID":         { "Type": "String" },
    "OrgPemID":          { "Type": "String" },
    "TrustedCertsPemID": { "Type": "String" }
  },

  "Mappings": {
    "RegionMap": <%= fragment(:ami_mappings) %>
  },

  "Resources" : {
    "SecurityGroup" : {
      "Type" : "AWS::EC2::SecurityGroup",
      "Properties" : {
        "GroupDescription" : "Enable SSH/HTTP/HTTPS",
        "SecurityGroupIngress" : [{
          "IpProtocol" : "tcp",
          "FromPort" : "22",
          "ToPort" : "22",
          "CidrIp" : { "Ref" : "SSHLocation" }
        }, {
          "IpProtocol" : "tcp",
          "FromPort" : "80",
          "ToPort" : "80",
          "CidrIp" : "0.0.0.0/0"
        }, {
          "IpProtocol" : "tcp",
          "FromPort" : "443",
          "ToPort" : "443",
          "CidrIp" : "0.0.0.0/0"
        }]
      }
    },
    "EC2Instance" : {
      "Type" : "AWS::EC2::Instance",
      "Properties" : {
        "InstanceType" : { "Ref" : "InstanceType" },
        "KeyName" : { "Ref" : "KeyName" },
        "ImageId" : { "Fn::FindInMap" : [ "RegionMap", { "Ref" : "AWS::Region" }, "AMI" ]},
        "Tags" : [
          {"Key" : "Name", "Value" : { "Ref": "InstanceName"}}
        ],
        "SecurityGroupIds" : [
          { "Ref" : "SecurityGroup" }
        ],
        "UserData": {"Fn::Base64": {"Fn::Join": ["", [
          "#! /bin/bash -v\n",

          "# Wait EIP assign\n",
          "sleep 60\n",

          "PublicDnsName=\"$(curl http://169.254.169.254/latest/meta-data/public-hostname)\"\n",

          "# For RabbitMQ. If HOME isn't set, RabbitMQ says 'erlexec: HOME must be set'\n",
          "export HOME=/root/\n",

          "echo '*** Fix Hostname ***'\n",
          "hostname ${PublicDnsName}", "\n",
          "sed -i -E \"s/^HOSTNAME=.+$/HOSTNAME=${PublicDnsName}/g\" /etc/sysconfig/network\n",
          "service network restart\n",

          "echo '*** Install Chef ***'\n",
          "cd /tmp/\n",


          "/opt/aws/bin/cfn-signal '", {"Ref": "wchDownloadChefPkg"}, "'\n",
          "rpm -Uvh ", {"Ref": "ChefPackageURL"}, "\n",


          "chef-server-ctl reconfigure\n",

          "yum install -y git \n",
          "cd /opt/\n",
          "git clone https://github.com/skyarch-networks/chefserver-internal-bootstrap-addon.git\n",
          "cd chefserver-internal-bootstrap-addon\n",
          "./install.sh\n",
          "cd /tmp/\n",

          "chef-server-ctl start\n",
          "/opt/aws/bin/cfn-signal '", {"Ref": "wchInstallChef"}, "'\n",
          "chef-server-ctl user-create ",
              {"Ref": "ChefUser"},     " ",
              {"Ref": "ChefFullName"}, " ",
              {"Ref": "ChefEmail"},    " ",
              {"Ref": "ChefPassword"}, " ",
              "--filename ", {"Ref": "ChefUser"}, ".pem\n",
          "chef-server-ctl org-create ",
              {"Ref": "ChefOrg"},     " ",
              {"Ref": "ChefFullOrg"}, " ",
              "--association_user ", {"Ref": "ChefUser"}, " ",
              "--filename ",         {"Ref": "ChefOrg"},  ".pem\n",

          "echo '*** Output files ***'\n",
          "/opt/aws/bin/cfn-signal ",
              "--id ", {"Ref": "UserPemID"},                     " ",
              "--data \"$(cat ", {"Ref": "ChefUser"}, ".pem)\"", " ",
              "'", {"Ref": "wchPemFiles"}, "'\n",
          "/opt/aws/bin/cfn-signal ",<commit_msg>Work bootstrap feature by fixing cf-template for chef server.<commit_after>{
  "AWSTemplateFormatVersion" : "2010-09-09",

  "Description" : "Chef Server for SkyHopper",

  "Parameters" : {
    "KeyName" : {
      "Description" : "Name of an existing EC2 KeyPair to enable SSH access to the instance",
      "Type" : "String"
    },
    "InstanceType" : {
      "Description" : "WebServer EC2 instance type",
      "Type" : "String",
      "Default" : "t2.small",
      "AllowedValues": <%= fragment(:ec2_instance_types_hvm) %>,
      "ConstraintDescription" : "must be a valid EC2 instance type."
    },
    "SSHLocation" : {
      "Description" : "The IP address range that can be used to SSH to the EC2 instances",
      "Type": "String",
      "MinLength": "9",
      "MaxLength": "18",
      "Default": "0.0.0.0/0",
      "AllowedPattern": "(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})/(\\d{1,2})",
      "ConstraintDescription": "must be a valid IP CIDR range of the form x.x.x.x/x."
    },
    "InstanceName": {
      "Description" : "Name of EC2 Instance",
      "Type" : "String",
      "Default": "Chef Server for SkyHopper"
    },

    "ChefPackageURL": { "Type" : "String", "Default": "https://web-dl.packagecloud.io/chef/stable/packages/el/6/chef-server-core-12.0.8-1.el6.x86_64.rpm" },
    "ChefUser":       { "Type" : "String", "Default": "skyhopper" },
    "ChefFullName":   { "Type" : "String", "Default": "<NAME>" },
    "ChefEmail":      { "Type" : "String", "Default": "<EMAIL>" },
    "ChefPassword":   { "Type" : "String", "Default": "<PASSWORD>" },
    "ChefOrg":        { "Type" : "String", "Default": "skyarch" },
    "ChefFullOrg":    { "Type" : "String", "Default": "Skyarch Networks Inc." },

    "UserPemID":         { "Type": "String" },
    "OrgPemID":          { "Type": "String" },
    "TrustedCertsPemID": { "Type": "String" }
  },

  "Mappings": {
    "RegionMap": <%= fragment(:ami_mappings) %>
  },

  "Resources" : {
    "SecurityGroup" : {
      "Type" : "AWS::EC2::SecurityGroup",
      "Properties" : {
        "GroupDescription" : "Enable SSH/HTTP/HTTPS",
        "SecurityGroupIngress" : [{
          "IpProtocol" : "tcp",
          "FromPort" : "22",
          "ToPort" : "22",
          "CidrIp" : { "Ref" : "SSHLocation" }
        }, {
          "IpProtocol" : "tcp",
          "FromPort" : "80",
          "ToPort" : "80",
          "CidrIp" : "0.0.0.0/0"
        }, {
          "IpProtocol" : "tcp",
          "FromPort" : "443",
          "ToPort" : "443",
          "CidrIp" : "0.0.0.0/0"
        }]
      }
    },
    "EC2Instance" : {
      "Type" : "AWS::EC2::Instance",
      "Properties" : {
        "InstanceType" : { "Ref" : "InstanceType" },
        "KeyName" : { "Ref" : "KeyName" },
        "ImageId" : { "Fn::FindInMap" : [ "RegionMap", { "Ref" : "AWS::Region" }, "AMI" ]},
        "Tags" : [
          {"Key" : "Name", "Value" : { "Ref": "InstanceName"}}
        ],
        "SecurityGroupIds" : [
          { "Ref" : "SecurityGroup" }
        ],
        "UserData": {"Fn::Base64": {"Fn::Join": ["", [
          "#! /bin/bash -v\n",

          "# Wait EIP assign\n",
          "sleep 60\n",

          "PublicDnsName=\"$(curl http://169.254.169.254/latest/meta-data/public-hostname)\"\n",

          "# For RabbitMQ. If HOME isn't set, RabbitMQ says 'erlexec: HOME must be set'\n",
          "export HOME=/root/\n",

          "echo '*** Fix Hostname ***'\n",
          "hostname ${PublicDnsName}", "\n",
          "sed -i -E \"s/^HOSTNAME=.+$/HOSTNAME=${PublicDnsName}/g\" /etc/sysconfig/network\n",
          "service network restart\n",

          "echo '*** Install Chef ***'\n",
          "cd /tmp/\n",


          "/opt/aws/bin/cfn-signal '", {"Ref": "wchDownloadChefPkg"}, "'\n",
          "rpm -Uvh ", {"Ref": "ChefPackageURL"}, "\n",


          "chef-server-ctl reconfigure\n",

          "yum install -y git \n",
          "cd /opt/\n",
          "git clone https://github.com/skyarch-networks/chefserver-internal-bootstrap-addon.git\n",
          "cd chefserver-internal-bootstrap-addon\n",
          "./install.sh\n",
          "cd /tmp/\n",

          "chef-server-ctl restart\n",
          "/opt/aws/bin/cfn-signal '", {"Ref": "wchInstallChef"}, "'\n",
          "chef-server-ctl user-create ",
              {"Ref": "ChefUser"},     " ",
              {"Ref": "ChefFullName"}, " ",
              {"Ref": "ChefEmail"},    " ",
              {"Ref": "ChefPassword"}, " ",
              "--filename ", {"Ref": "ChefUser"}, ".pem\n",
          "chef-server-ctl org-create ",
              {"Ref": "ChefOrg"},     " ",
              {"Ref": "ChefFullOrg"}, " ",
              "--association_user ", {"Ref": "ChefUser"}, " ",
              "--filename ",         {"Ref": "ChefOrg"},  ".pem\n",

          "echo '*** Output files ***'\n",
          "/opt/aws/bin/cfn-signal ",
              "--id ", {"Ref": "UserPemID"},                     " ",
              "--data \"$(cat ", {"Ref": "ChefUser"}, ".pem)\"", " ",
              "'", {"Ref": "wchPemFiles"}, "'\n",
          "/opt/aws/bin/cfn-signal ",
{'fraction_non_alphanumeric': 0.221585293536272, 'fraction_numerical': 0.017197074520656257, 'mean_word_length': 1.9570426651081239, 'pattern_counts': {'":': 100, '<': 12, '<?xml version=': 0, '>': 12, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 8, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6807224', 'n_tokens_mistral': 3659, 'n_tokens_neox': 3504, 'n_words': 667}