Variable precedence in Ansible

by XDK 24. September 2019 05:41


Following are the levels of variable precedence arranged from the least (always gets overridden) to the most (can override anything below it):
1. Role defaults
2. Inventory files (host_vars > group_vars > vars)
3. Playbook group_vars
4. Playbook host_vars
5. Host facts
6. Variables files > vars_prompt > vars
7. Variables created using the register clause
8. Variables files created inside Roles and those set by the include_vars module
9. Variables defined in a block
10. Variables defined in a task block
11. Any variables passed through -e during command execution



How to find the command execution status?

by XDK 23. September 2019 08:29


Command to view the execution status

$ echo $?

Exit status output will be 0,1 or 2 where 0 --> Success, 1 --> Minor problems and 2 --> Serious problem



Docker Cheat Sheet for Ubuntu

by XDK 19. September 2019 18:37

Tags: ,

Amazon Web Service | Docker

EC2 instance user data is not executed.

by XDK 18. September 2019 22:27
The user data is not executed due to the leading whitespaces in the following format
resource "aws_instance" "Terraform-Demo" {
  ami = "${lookup(var.RegionToAmazonAMI, var.Region)}"
  instance_type = "t2.micro"
  key_name = "myaccountkey"
  vpc_security_group_ids =  ["${}"]
  user_data = <<EOF
    #! /bin/bash
    sudo apt update
    sudo apt install -y apache2
    sudo chmod 777  /var/www/html
    sudo echo "Terraform instance 2 with IP IP_ADDR" > /var/www/html/index.html
    sudo echo "Terraform instance 2 with IP IP_ADDR -- OK" > /var/www/html/health.html
  provisioner "local-exec" {
    command = "echo ${aws_instance.Terraform-Demo.public_ip} > testP.txt"
  tags = {
    Name = "TerraformDemo"
Either add hyphen in <<-EOF to trim the leading whitespaces or remove the whitespaces manually 


Amazon Web Service | Terraform

EC2 instances launched in the subnet missing public IPv4 address

by XDK 18. September 2019 22:09

EC2 instances launched in the subnet using Terraform or Cloudformation is missing public IPv4 address

Add the following argument/property


MapPublicIpOnLaunch - Indicates whether instances launched in this subnet receive a public IPv4 address.

Type: 'AWS::EC2::Subnet'
- '0'
- Fn::GetAZs:
Ref: 'AWS::Region'
CidrBlock: ''
MapPublicIpOnLaunch: 'True'
Ref: 'VPC'
- Key: 'Name'
'Fn::Join': [ ':', [ 'Public', 'Zone A', !Ref 'AWS::StackName' ] ]


map_public_ip_on_launch - (Optional) Specify true to indicate that instances launched into the subnet should be assigned a public IP address. Default is false.

resource "aws_subnet" "public-subnet-a" {
vpc_id = "${}"
map_public_ip_on_launch = true
cidr_block = ""
availability_zone = "${data.aws_availability_zones.available.names[0]}"
tags = {
Name = "public-subnet-a:${var.labname}"


Amazon Web Service | Terraform | CloudFormation

About the author

My name is Xavier Dilip Kumar Jayaraj having 13+ years of IT experience which includes solid experience and depth Knowledge in Application Life Cycle Management, Configuration Management, Implementation and Support using TFS on-premises and Azure DevOps. I have invested in gaining DevOps knowledege to expertise with Cloud Computing providers namely Microsoft Azure and Amazon Web Services in recent years. I am very positive to learn and adapt emerging technologies to client’s environment.

Microsoft Certified: Azure Administrator Associate

Microsoft Certified: Azure DevOps Engineer Expert

DevOps Engineer Certificate Program | Transcript 

OTP-AWSD5: AWS IoT: Developing and Deploying an Internet of Things

[PCEP-30-01] PCEP – Certified Entry-Level Python Programmer

Quotes I Like

"Failure will never overtake me if my determination to succeed is strong enough."  - Dr. APJ. Abdul Kalam

"Always be yourself, express yourself, have faith in yourself, do not go out and look for a successful personality and duplicate it." - Bruce Lee

"Technology is just a tool. In terms of getting the kids working together and motivating them, the teacher is the most important." - Bill Gates

"Innovation distinguishes between a leader and a follower." - Steve Jobs



The information provided here is based on my expreriences, troubleshooting and online/offline findings. It can be used as is on your own risk without any warranties and I impose no rights.