Tuesday, 27 December 2016

Ansible: How to run local action

In this article, we will learn some of the use-cases and advantages of Ansible local_action.

Ansible local_action module:


Consider the problem / usecase scenario where we want to run tasks on the system which runs the Ansible-playbook command. In other words, how can we run for eg. shell command on the local machine parallely while playbook is already running. Also, how can we make sure that some tasks has been fulfilled in order to run the other part of playbook on some other remote machine.

The solution to the above usecase is the local_action option provided by Ansible. It takes the module name and module argument and will run that module locally.

Example:




cat local_action.yml

---

- hosts: dev

  tasks:

    - name: remote running process

      shell: ps

      register: remote_process



    - debug: msg="{{ remote_process.stdout }} "



    - name: Running Local Process

      local_action: shell ps

      register: local_process



    - debug: msg="{{ local_process.stdout }}"

 

Consider this example, which is the playbook I will be using for local_action. If we run the above playbook, we can see that we have two tasks.



- name: remote running process

   shell: ps

   register: remote_process



 - name: Running Local Process

   local_action: shell ps

   register: local_process

 

Ansible local_action shell

The first task will run ps command (shell command) on the remote machine and to check the output of the command a register remote_process has been set.

The second task as shown in above example will run command on local machine due to the local_action module being specified.

How to run local actions?

To run local actions, we just need to define the module name (i.e. local_action module name) for the command or task to run.

For example:




ansible-playbook local_action.yml



PLAY [dev] ********************************************************************



GATHERING FACTS ***************************************************************

ok: [172.16.202.96]



TASK: [remote running process] ************************************************

changed: [172.16.202.96]



TASK: [debug msg="{{ remote_process.stdout }} "] ******************************

ok: [172.16.202.96] => {

    "msg": "  PID TTY          TIME CMD\n12775 pts/1    00:00:00 sh\n12776 pts/1    00:00:00 python\n12777 pts/1    00:00:00 ps "

}



TASK: [Running Local Process] *************************************************

changed: [172.16.202.96 -> 127.0.0.1]



TASK: [debug msg="{{ local_process.stdout }}"] ********************************

ok: [172.16.202.96] => {

    "msg": "  PID TTY          TIME CMD\n24362 pts/0    00:00:02 bash\n30565 pts/0    00:00:00 ansible-playboo\n30587 pts/0    00:00:00 sh\n30588 pts/0    00:00:00 python\n30593 pts/0    00:00:00 ps"

}



PLAY RECAP ********************************************************************

172.16.202.96              : ok=5    changed=2    unreachable=0    failed=0 




Analysis:

If we see the above command result, we find that the both output differ from each other because one is being run on local macine and another being run on remote machine.

Ansible local_action sudo:

If we want to make anisible use the remote user for local_action, use the -u option while running playbook. When it uses the user to sudo, it will ask for sudo password



ansible-playbook -i <inventory> ansible/local_action.yml -u <local user that can sudo with password> --ask-sudo-pass


Conclusion:

Ansible local_action is the way to make double sure that the some things are available before we jump to run on remote machine. Its like running pretest locally before running command or task on remote machine.

Thats all about Ansible local_action usage and its purpose.

Puppet Interview Questions

What is Puppet?
Puppet is the configuration management tool for unix based and windows systems. 
What is puppet manifest?
What is manifest ordering and its importance?
What is puppet module?
Why Puppet matters to Devops? (Advantage of Puppet over other devops tools)
What is puppet catalog?
Can you describe the puppet module layouts / structure?
What are agent nodes?
What is EPP templates?
What is the use of Puppet DB?
What is the use of filebucket in puppet?
How do you perform dry run? (no-op / noop)
What is virtual resource in puppet?
How can you realize a virtual resource?
Is puppet resource idempotent
What is the purpose of Hiera tools?
Which node is called masterless node?
How can you manage nodes using Node Manager?

Sunday, 23 October 2016

Jenkins Interview Questions and Answers for experienced

Jenkins is one of the tools for continuous integration and these days more applications are using Jenkins for automated integration. Here are few important questions and answers on Jenkins.

1. What is Jenkins?

Jenkins is an open source application for continuous integration and continuous delivery of application software.

2. What is Continuous Integration?

Typically, there are multiple developers writing code for a single application, so we need to perform integration test by integrating each new piece of code via testing it through as many tests as possible. This practice is called continuous Integration. Jenkins besides Hudson, Bamboo etc provides tools for continuous integration.

3. Tell me few advantages of Jenkins?

Here are some advantages of using Jenkins (or by any matter any integration tools) :-

(a) It saves developer time: 

The foremost advantage of using Jenkins is that since most of the integration task is being handled by Jenkins (via automatic integration), the developer time is focused on development activities mostly.

(b) Improved software quality

Since the software is being tested immediately after any code check-in, it keeps the quality check frequently, thus improving overall software quality.

(c) Faster Delivery

Jenkins automatically does continuous integration, which leads to very early detection of bugs / defects and hence it leads to faster delivery of software.

(d) Decreased development time

Since most of the integration work is automated by Jenkins, it leads to the faster development of application.

(e) Easily portable: 

Since Jenkins is developed using Java, it can be easily portable to other platforms.

(f) Early tracking of defects: 

Jenkins helps tacking of defects at very early stage in development environment only rather than production environment.

(g) Email Notification to developers: 

Jenkins can be easily integrated with LDAP server, so developer are notified about build success / failure via mail.

4. What are the commands to start Jenkins manually?

Commands:
<jenkins_url>/restart :  Force restart (will not wait for ongoing build to complete)
<jenkins_url>/safeRestart : Wait for all builds to complete before restarting.

5. Mention few plugins of Jenkins?

Here are some plugins that can be used with Jenkins:

  • Delivery Pipeline
  • Join Plugin
  • Copy Artifact 
  • Git 
  • Android Emulator 
  • Cobertura 
  • Email-ext 
  • Docker 
  • Amazon EC2
  • Openstack Cloud
  • CloudBees Folders

6. What are the two most important components Jenkins is integrated with?

Jenkins is integrated with these two components mainly:
(a) Version Control System like SVN, GIT
(b) Build tools like Maven



That's all for some important questions and answers on Jenkins. I will add more questions and answers later.