jeudi 30 juillet 2015

Chef aws driver tags don't work using Etc.getlogin

I am currently using Chef solo on a Windows machine. I used the fog driver before which created tags for my instances on AWS. Recently, I moved to the aws driver and noticed that aws driver does not handle tagging. I tried writing my own code to create the tags. One of the tags being "Owner" which tells me who created the instance. For this, I am using the following code:

  def get_admin_machine_options()
    case get_provisioner()
    when "cccis-environments-aws"

      general_machine_options = {ssh_username: "root",
        create_timeout: 7000,
        use_private_ip_for_ssh: true,
        aws_tags: {Owner: Etc.getlogin.to_s}
      }

      general_bootstrap_options = {
        key_name: KEY_NAME,
        image_id:  "AMI",
        instance_type: "m3.large",
        subnet_id: "subnet",
        security_group_ids: ["sg-"],
      }

      bootstrap_options = Chef::Mixin::DeepMerge.hash_only_merge(general_bootstrap_options,{})

      return Chef::Mixin::DeepMerge.hash_only_merge(general_machine_options, {bootstrap_options: bootstrap_options})

    else
      raise "Unknown provisioner #{get_setting('CHEF_PROFILE')}"
    end
  end

  machine admin_name do
        recipe "random.rb"
        machine_options get_admin_machine_options()
        ohai_hints ohai_hints
        action $provisioningAction
  end

Now, this works fine on my machine. The instance is created on my machine with proper tags but when I run the same code on someone else's machine. It doesn't create the tags at all. I find this to be very weird. Does anyone know what's happening? I have the same code!




Aucun commentaire:

Enregistrer un commentaire