Posts

Showing posts from August, 2021

Ansible Comparison Membership Operators

Image
Hello everyone are you working on Ansible Automations?!!  This is post is for you to help, In this post you will find more interesting variable usages and their operations with different options such as comparison operators and membership operators. Comparison operators This is an example for Comparison operators --- # Filename: test_compare.yml - name: Comparison Operator example hosts: localhost gather_facts: false vars: a: "Vybhava" b: "Technologies" n: 100 m: 500 tasks: - debug: msg: - "This will compare numbers {{n}} and {{m}} " - " n == m: {{ n == m }}" - " n != m: {{ n != m }}" - " n > m: {{ n > m }}" - " n >= m: {{ n >= m }}" - " n <= m: {{ n <= m }}" - " n < m: {{ n < m }}" - "Compare Strings : a {{a}} and b {{b}}" - " a ==...

Ansible 11 The uri module with examples

Image
 Hey DevSecOps Automation specialist, Welcome back to the DevOps Hunter blog. In this post, I made it for learning more about all possible parameters that we can use when an application validation is done with the Ansible 'uri' module.  Why uri module? Web Application returns status HTTPCode 200 for success, 404 for failures, and also for 503 for Server internal issues. When you work on the restart of a web application we need to know the status of the application to proceed with the next move. So this uri module is most important for reboot and restart of web applications using ansible. The uri module parameters Supported parameters include: attributes, backup, body, body_format, client_cert, client_key, content, creates, delimiter, dest, directory_mode, follow, follow_redirects, force, force_basic_auth, group, headers, http_agent, method, mode, owner, regexp, remote_src, removes, return_content, selevel, serole, setype, seuser, src, status_code, timeout,...

Ansible 10 Shell vs Command module

Image
Hello DevSecOps Automation learners!! You can do wonders by learning Ansible Automations along with me. The Ansible can run the command module as default that is you don't need to mentioned with -m option for command. That means when you don't mention any module then it is working with the 'command module' Ansible Shell vs Command module Here we will execute in details of experiment with 4 different use cases which could be part of your automation playbook construct: Both operate similarly When redirect operator used When pipes used between commands Multiple commands need to run Let's examine these use cases 1. Both operate similarly If we need to run single Linux command to be executed then both shell, commands modules operates same way there is no difference. Here I'm using "who -r" command to be run. If we don't mention any module name then command module by default. # Using default command module ansible web -a "who -r" #or ansible...

Ansible 5: Commands and their examples

Image
Hello Automation specialists, This post is for trying all the Ansible Command-line tools,  it's like a cheat sheet for ansible CLI with executed examples to better understand their usage. Ansible command-line utilities can be executed only on the box where the Ansible engine is installed and running. ansible  ansible command is used for define and run a single task 'playbook' against a set of hosts. ansible command is an extra-simple tool/framework/API for doing 'remote operations'.   Case 1: ansible -i inventory.yml all --list-hosts # all ansible -i inventory.yml dbserver --list-hosts #Specific group ansible -i inventory.yml common --list-hosts # same as all if inventory is yml Listing host using ansible command Case 2: # inventory set in the ansible.cfg ansible all --list-hosts # a group specific ansible web --list-hosts # checking for a specific host in a group ansible web --list-hosts -l 192.168.33.22...

Ansible 6 Understanding host_vars and group_vars

Image
In this post, we will discuss the possible options for ansible variables precedence, Experiment with few host_vars, group_vars, and their variable precedence. You can specify the variables along with the host inside your inventory itself.  Ansible host_vars and group_vars and usage options The command-line variable will be the highest priority. To test the variable precedence, top priority extra vars ansible -i "node1," all \ -e "var1=VybhavaTechnologies" \ -m debug -a 'msg={{ var1 }}' Here -i use the target host and the group name to define an extra variable that will have the highest priority. Using debug module we can get the var1 value using jinja format to print. ansible extra variables highest precedence  Let's see the following example:   Create the inventory.yml file in "dev" directory. inventory.yml all: children: common: children: webserver: hosts: node[1:2]: ...

Ansible 9 Custom Roles - Reusability

Image
Hello Guys, welcome back to DevSecOps Automations!! In this post, we will be exploring the Custom role create and usage in a playbook, which is a most industry requirement. It depends on your use cases. It's always recommended to write a role if you have a complex set of tasks consist of handlers and jinja templates. Roles break down a complex playbook into simple and multiple reusable plays easy to read! In the last post, we have learned about how ansible-galaxy helps us to install, create, modify the ready-made roles which are provided by the Ansible community freely on the Galaxy site. What are the roles why we should use them in Ansible? As per my understanding so far following points : A role can be defined when we have to do one or many tasks It is a set of tasks with a single objective (for example reboot of box - stop all process, reboot, start process) You can organize the code in more readable form using roles it is like functions in Python or C  Here the main objective i...

Ansible Reusability with roles and ansible galaxy

Image
Ansible Roles In this post, I've gone thru multiple articles and YouTube videos on 'ansible roles', which helped me to understand into a deeper level of Ansible roles and galaxy site and CLI commands with various options. So, sharing here with you   What is role in Ansible? The role is the primary mechanism for breaking a playbook into multiple files. This simplifies writing complex playbooks, and it makes them easier to reuse.  Why should I use Roles in Ansible? The following are the reasons to work with roles Address complexity Reusability and sharing Modular code Learn how to build and create ansible roles to manage remote machines using an ansible configuration management tool.  For example let's create an apache role to install, configure and easy to manage the Apache web server using the roles.  Ansible Galaxy ansible roles structure Defining Ansible Roles are having major role in simplifying a larger playbook split into multiple small files called roles ...