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)