How to : Docker mount current working directory as volume

Hello Everyone,

If you have a docker container and you would like to mount one of your current folder in the host machine as volume inside your container, then you can use below command


docker run --rm -it -v $(pwd):/usr/src/project gcc:4.9
 

use cases:

- If you local folder have your source code and you like to execute inside your container environment manually. 

How To - Ansiable Playbook Output - JSON Format

How To - Ansiable Playbook Output - JSON Format

Hello Everyone,

In this blog post lets see how to execute ansible-playbook with custom output format like JSON

Lets say you have a playbook like below

---
- hosts: 127.0.0.1
  gather_facts: false

  tasks:
    - name: execute uptime command
      command: uptimer
      register: result

    - debug: var=result.stdout

And if you execute the playbook with below command

ansible-playbook playbook.yaml

You will get normal ansible standard output format like below

▶ ansible-playbook ansible_uptime.yaml
[WARNING]: No inventory was parsed, only implicit localhost is available
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'

 _______________________________
< TASK [execute uptime command] >
 -------------------------------
      
changed: [127.0.0.1]

ok: [127.0.0.1] => {
    "result.stdout": "12:34  up  4:03, 2 users, load averages: 3.42 3.62 3.10"
}


127.0.0.1 : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0


~/my_learning/ansible

If you want output in JSON format for example, you can use ANSIBLE_STDOUT_CALLBACK env variable. Set the variable value with respect to output format you want. If its JSON

ANSIBLE_STDOUT_CALLBACK=json ansible-playbook ansible_uptime.yaml
▶ ANSIBLE_STDOUT_CALLBACK=json ansible-playbook ansible_uptime.yaml
[WARNING]: No inventory was parsed, only implicit localhost is available
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'
{
    "custom_stats": {},
    "global_custom_stats": {},
    "plays": [
        {
            "play": {
                "duration": {
                    "end": "2021-10-26T07:06:58.968665Z",
                    "start": "2021-10-26T07:06:58.419247Z"
                },
                "id": "acde4800-1122-4989-e4cc-000000000005",
                "name": "127.0.0.1"
            },
            "tasks": [
                {
                    "hosts": {
                        "127.0.0.1": {
                            "_ansible_no_log": false,
                            "action": "command",
                            "changed": true,
                            "cmd": [
                                "uptime"
                            ],
                            "delta": "0:00:00.008988",
                            "end": "2021-10-26 12:36:58.904425",
                            "invocation": {
                                "module_args": {
                                    "_raw_params": "uptime",
                                    "_uses_shell": false,
                                    "argv": null,
                                    "chdir": null,
                                    "creates": null,
                                    "executable": null,
                                    "removes": null,
                                    "stdin": null,
                                    "stdin_add_newline": true,
                                    "strip_empty_ends": true,
                                    "warn": false
                                }
                            },
                            "msg": "",
                            "rc": 0,
                            "start": "2021-10-26 12:36:58.895437",
                            "stderr": "",
                            "stderr_lines": [],
                            "stdout": "12:36  up  4:05, 2 users, load averages: 3.78 3.54 3.14",
                            "stdout_lines": [
                                "12:36  up  4:05, 2 users, load averages: 3.78 3.54 3.14"
                            ]
                        }
                    },
                    "task": {
                        "duration": {
                            "end": "2021-10-26T07:06:58.942858Z",
                            "start": "2021-10-26T07:06:58.448326Z"
                        },
                        "id": "acde4800-1122-4989-e4cc-000000000007",
                        "name": "execute uptime command"
                    }
                },
                {
                    "hosts": {
                        "127.0.0.1": {
                            "_ansible_no_log": false,
                            "_ansible_verbose_always": true,
                            "action": "debug",
                            "changed": false,
                            "result.stdout": "12:36  up  4:05, 2 users, load averages: 3.78 3.54 3.14"
                        }
                    },
                    "task": {
                        "duration": {
                            "end": "2021-10-26T07:06:58.968665Z",
                            "start": "2021-10-26T07:06:58.949451Z"
                        },
                        "id": "acde4800-1122-4989-e4cc-000000000008",
                        "name": "debug"
                    }
                }
            ]
        }
    ],
    "stats": {
        "127.0.0.1": {
            "changed": 1,
            "failures": 0,
            "ignored": 0,
            "ok": 2,
            "rescued": 0,
            "skipped": 0,
            "unreachable": 0
        }
    }
}

~/my_learning/ansible

Hope it helps.

Thank you.
Raaz

Motivation for everyone for everyday in real life or work life, Read this everyday before starting your day

When something is fun,like playing cricket, watching a suspense thriller or Sci-Fi movie, you dont need extra motivation, you will do that anyway because you are loving it. When something isn't fun, you dont like it and if you still have to do it, then you can follow below ideas.

  • Dont just go with problem -> solution approach, if you have 10 problems, if you have solved 3 already then you still see them as 7 more PROBLEMS and our brain hate problems, wont it ?, so its no more fun, so it (you) started doing procrastination automatically and soon or later you reach deadlines and you started feeling guilty for wasting that much time and you will hurry up with your work and finally your work from making a spider in 10 minutes to making a spider to 1 minute

 Image credit : https://jim.blacksweb.com

  •  So look at them like with explorer mindset. You remember in explorer games you have to do lot of exploring for gems, points etc. So adopt same satisfying or happy mindset when you started exploring a problem and found a solution. Dont look at them like problems, look at them like something you dont know and need to explore.

 

  •  Dont get overwhelm by things you dont know. Break the problem into steps. Users are unable to login into your billion dollars application, this reason is enough to create panic, heart attacks. But look at the problem, " ok no login, alright, login page loading properly ? on submit event coming to our webservers or not ? if no , ok network issue, call network team. if, yes, ok from here request is sending to respective logic server/ app server or not ? no , check the LB, check the VIP rules, check webserver configuration etc." like this you can formulate so many steps and you can solve the problem or atleast you can identify and understand the problem and then giving a solution can be easy because you know the problem already, "" Some problems are tricky I agree and might needs more brains, so thats why we work in a team right, take their suggestion, because greatest things were never built alone "".

 

  • Expect always that nothing is perfect and when you got a problem, see it like an opportunity to improve your self for next product/ design to avoid same/similar issues like this. See it like a way of improving your current product, to make it more solid. so problems are good, they will help you and your product, to more solid product. And as you have faced the problem, your next product must consider this type of issue, so your next product is already bullet proof for current problem you are facing. You might get new problems, but they are chances to improve yourself or your product always. They are coming to make you strong, not to make you week. 

Hope it help you. Please add your comments, if you like this post and that will gives me a clarity if I need to write more in future. 

 

Linux: How to remove directory / folder background color in terminal ?

Hello Everyone,

I moved to Ubuntu Linux recently from Arch Linux. I observed that my battery ( Lenovo Thinkpad E Series 3rd Gen) health getting low by using Arch Linux and there were some posts on that issue.

Though Arch Linux is great, I dont want to loose my $1000 laptop battery as I invested extra bucks especially for battery with extra capacity.

Any way, as I am using dual boot with Windows and Linux, I do have NTFS partitions.

As per color scheme of the terminal, if you list the items in the NTFS mount in terminal, they all come up with an ugly look as below


 so as you can see it, its completely not good.

So upon searching I came across below solution via Stackoverflow

If you are using zsh then open file ~/.zshrc, if bash then ~/.bashrc and paste following code at the end, save and exit from the file. Once exited, execute exec $SHELL  command, and it equal to source ~/.zshrc or source ~/.bashrc

eval "$(dircolors -p | \
   sed 's/ 4[0-9];/ 01;/; s/;4[0-9];/;01;/g; s/;4[0-9] /;01 /' | \
   dircolors /dev/stdin)"

So after applying the changes, my terminal output is clear as below

Hope it helps you.


Thank you.