Tuesday, January 3, 2017

Chef: databag: issues


Error1:
 chef (12.17.44)> klam_ssh_conf = Chef::EncryptedDataBagItem.load('hubvpc', 'prod_secrets', IO.read('/etc/chef/hubvpc_prod_key'))['klam']   Chef::EncryptedDataBagItem::DecryptionFailure: Error decrypting data bag value: 'bad decrypt'. Most likely the provided key is incorrect.

issues: 
  1) encrypted key is wrong.
  2) encrypted key is corrupted during copy-paste. (will work with knife though)
       => do a   $ cat enc.key | tr -d '\r\n' > enc_new.key

=======================================================================

Friday, July 15, 2016

chef client - errors

Problem 1
a) >> node.fqdn
Undefined method or attribute `fqdn' on `node'
b) "hostname -f" or "hostname -a" giving "Unknown host"

Solution: make sure sure host is resolvable, if not then make the entry is in /etc/hosts

===============================================================

Tuesday, February 16, 2016

docker: local creds server


Step1: pull credentials from cyberark vault and add end point details from cloudformation output. (in jenkins)

Step2: Create json with above info. (in jenkins)

Step3: Jenkins job comprising of below steps:
a. move above json to http document root.
b. start apache server with access locally limited.

Step4: Docker file needs to comprise of below actions
a. yum install curl jq
b. curl -s http://some-endpoint/some.json | jq  --raw-output '.dev.frontend.password'

Step5: Jenkins "create-docker-image-xyz" to perform below steps:
a. create image based on above docker file.
c. trigger cleanup job:
i. stop apache.
ii. remove json

* We can even encrypt the passwords as well.

Here is the sample json file:

{
  "dev" : {
    "frontend" : {
      "username" : "xyz",
      "password" : "somepass"
    },
    "backend" : {
      "username" : "xyz",
      "password" : "somepass"
    }
  },
  "stage" : {
    "frontend" : {
      "username" : "xyz",
      "password" : "somepass"
    },
    "backend" : {
      "username" : "xyz",
      "password" : "somepass"
    },
    "worker" : {
      "username" : "xyz",
      "password" : "somepass"
    }
  },
  "prod" : {
    "frontend" : {
      "username" : "xyz",
      "password" : "somepass"
    },
    "backend" : {
      "username" : "xyz",
      "password" : "somepass"
    }
  }

}

Tuesday, February 9, 2016

Chef: Retry (or sleep) some resource, in case the it's waiting for other resource to be up.

Use Case: need to validate tomcat healthcheck.

execute "validate_docker" do
  command "docker ps"
  action :run
  retries 6
  retry_delay 10
  notifies :run, 'execute[start_ecs]', :immediately
end

retries: The number of times to catch exceptions and retry the resource. Default value: 0.
retry_delay: The retry delay (in seconds). Default value: 2.

Wednesday, February 3, 2016

route53 : windows: change resource record fails with Paramter validation error

Error:
1) 'ascii' codec can't encode character u'\xff' in position 26: ordinal not in range(128)
2) Parameter validation failed:
Invalid type for parameter ChangeBatch.Changes[0].ResourceRecordSet.TTL, value:
120, type: <type 'unicode'>, valid types: <type 'int'>, <type 'long'>
Invalid type for parameter ChangeBatch.Changes[0].ResourceRecordSet.ResourceRec
rds, value: ue1010248068100.corp.adobe.com, type: <type 'unicode'>, valid types
 <type 'list'>, <type 'tuple'>

Reason: Due to Encoding

Remedy:
# Create file for Route53
$X=@"
{
  "Comment": "Route53 Weighted Routing - $SID with value $Weight",
  "Changes": [
    {
      "Action": "UPSERT",
      "ResourceRecordSet": {
        "Name": "$MYCNAME",
        "Type": "CNAME",
        "SetIdentifier": "$SID",
        "Weight": $Weight,
        "TTL": 120,
        "ResourceRecords": [{"Value": "$FQDN"}]
      }
    }
  ]
}
"@
$X | out-file -Encoding ASCII  C:\r53.json

# Set CNAME
(aws --region $AWSREGION route53 change-resource-record-sets --hosted-zone-id $Route53zone  --change-batch file://C:\r53.json)

Thursday, December 17, 2015

Chef: Template: erb tags

Here are the ERB ruby tags used in templates:


<% and %> Executes the ruby code within the brackets.

<%= and %> Prints something into erb file.

<% and -%> Avoids line break after expression.

<%# and %> Comments out code within brackets; not sent to client (as opposed to HTML comments).

Thursday, September 10, 2015

Chef: "ec2" node attribute missing

You can get the ec2 node attribute by creating ec2.json file. Once the node is bootstrappped all of your ec2 metadata will be available in ohai!

a. Linux
            $ touch /etc/chef/ohai/hints/ec2.json

b. Windows
$ mkdir C:\chef\ohai\hints
$ copy /y nul  C:\chef\ohai\hints\ec2.json


========================================================================
In the case that you are using chef-provisioning to provision and bootstrap nodes you can include the following in your machine resource call:

ohai_hints 'ec2' => '{}'

This effectively accomplishes the same thing. Its a neat trick that will save you a bunch of time when you need to manipulate a node based off of specific ec2 metadata.