How does Ansible Reboot work

How does Ansible Reboot work
Techiio-author
Written by Nilima PaulFebruary 8, 2022
10 min read
Ansible
2 VIEWS 0 LIKES 0 DISLIKES SHARE
0 LIKES 0 DISLIKES 2 VIEWS SHARE
Techiio-author
Nilima Paul

Technology Security Analyst

In this blog post, We will discuss Ansible Reboot.

Introduction of Ansible Reboot

Ansible gives a lot of modules that are immediate substitutions of our Unix/Linux orders, yet can work preferably over involving those comparable orders in scripts. One such module is the Ansible reboot module. This module is a substitution of reboot order on Linux/Unix frameworks yet can work in a better way. This implies we can reboot the remote objective machines for certain checks and extra postponements pre and post-reboot. For Microsoft Windows conditions, we have a comparable module named win_reboot.

What is Ansible Reboot?

This module fundamentally is utilized for rebooting a machine, hanging tight for effective halting, and beginning then, at that point, reacting to test orders, to affirm reboot was fruitful. On Linux/Unix machines, it essentially summons closure order accessible under one of the ways/bin,/usr/bin,/usr/nearby/in. The way of closure order can be given physically by boundary way.

How does Ansible Reboot work?

Like some other Ansible Module, the Ansible reboot module is outfitted with a bunch of boundaries and satisfactory qualities. A portion of these boundaries has default values that will be acknowledged in your playbook regardless of whether you notice the connected boundary in the playbook. So these become more vital to know.

Given beneath are a rundown of every single accessible boundary and related adequate or default values.

  • test_command: This boundary is utilized to provide the order on rebooted has after reboot task and anticipate that achievement should affirm whether the machine is prepared for next undertakings in the playbook. The default order is "whoami".
  • search_paths: This is to give the areas to look for closure orders on remote objective machines. At the point when this is utilized then PATH climate variable will be Default is/sbin,/usr/bin, and/neighborhood/use/bin.
  • reboot_timeout: This time is like a flash and to determine an opportunity to trust that the machine will reboot and react to a test order. This will be assessed independently for check and test order achievement. And that implies the greatest measure of time for execution is two times of this worth. Of course, it is set to 600 seconds.
  • pre_reboot_delay: Time to stand by before reboot, this will be set as a boundary to reboot On *nix-based machines, this is determined on minutes premise, implies seconds changed over to minutes and adjusted down. On the off chance that under 1 moment, it takes like 0. Default is 0.
  • post_reboot_delay: This is time in seconds to pause, after reboot. Before endeavoring to approve the framework reboot. This is helpful to settle down something after reboot. Default is 0.
  • connect_timeout: how much time in seconds to sit tight for fruitful association after reboot, before attempting once more.
  • msg: Default message is "Reboot Initiated by Ansible". This is to determine the message to show to working clients before rebooting.

Given beneath are the bring values back:

  • passed: The time slipped by hanging tight for a reboot.
  • rebooted: True on the off chance that the machine was effectively rebooted.

Examples of Ansible Reboot

Given underneath are the models referenced:

Here we have one Ansible regulator hub named as ansible-regulator. As target hubs, we have two remote machines. The first machine is a Red Hat Enterprise Linux machine named host-one and the second machine is a Ubuntu machine named host-two. We will run our playbooks on the Ansthe ible regulator machine and make changes on remote objective machines.

Example #1

In this example, we have a playbook like below where we are simply rebooting the target machines.

Code:

---
- hosts:
all
tasks:
- name: Here we are rebooting the remote machines. reboot:

Running this playbook like below with some verbosity:

ansible-playbook ansible_reboot.YAML -v

In the output, we can see all the outputs and returned values to figure out how much time it took and whether the reboot was successful.

ansible-playbook --syntax-check ansible_reboot.YAML

Output:

blogpost

Example #2

In this model, we have a playbook underneath where we are rebooting the objective machines with some pre and post postponement and afterward have an order to test the server is up and prepared for the next assignments. Here we have utilized test order as "uptime" rather than default "whoami".

Code:

---
-hosts:
all
tasks:
-name: Here we are checking the time on remote machines before shell: date
-name: Here we are rebooting with some reboot:
pre_reboot_delay: 10
post_reboot_delay: 10 test_command: uptime
-name: Here we are checking the time on remote machines after shell: date

Running this playbook like below with some verbosity:

ansible-playbook ansible_reboot_with_parameters.yaml -v

In the output, we can see all the outputs and returned values to figure out how much time it took with the output of the test command.

Output:

blogpost

Example #3

In this model, we have a playbook like beneath where we are rebooting the objective machines with a test order to make an example record on remote machines. This is to confirm that test orders got executed for confirmation of reboot.

Code:

---
-hosts:
all
tasks:
-name: Here we are checking the time on remote machines before shell: date
-name: Here we are rebooting with some reboot:
test_command: touch /var/tmp/reboot_1.txt
-name: Here we are checking the time on remote machines after shell: "ls -l /var/tmp/reboot_1.txt; date"

Now running this playbook like below:

ansible-playbook ansible_reboot_with_parameters.YAML -v

In the below output we can see all the time captured before and after reboot and also the file created as reboot verification.

Output:

blogpost

Conclusion

As we found in this article, Ansible Reboot is a module that you will require, without a doubt, in your everyday organization or change the executive's assignments. This module furnishes your capacity to work with reboots insightfully. Yet, this module will reboot the remote machines which can prompt vacation or blackout. So you should just involve this in arranged exercises. So learn it first and afterward use it.

Ansiblereboot
Ansible
yaml
2 VIEWS 0 LIKES 0 DISLIKES SHARE
0 LIKES 0 DISLIKES 2 VIEWS SHARE
Was this blog helpful?
techiio-price-plantechiio-price-plantechiio-price-plantechiio-price-plantechiio-price-plan
You must be Logged in to comment
Code Block
Techiio-author
Nilima Paul
Technology Security Analyst
Techiio-followerTechiio-followerTechiio-follower
201 Blog Posts
0 Discussion Threads
Trending Technologies
15
Software40
DevOps47
Frontend Development24
Backend Development20
Server Administration17
Linux Administration26
Data Center24
Sentry24
Terraform23
Ansible83
Docker70
Penetration Testing16
Kubernetes21
NGINX20
JenkinsX17
Techiio-logo

Techiio is on the journey to build an ocean of technical knowledge, scouring the emerging stars in process and proffering them to the corporate world.

Follow us on:

Subscribe to get latest updates

You can unsubscribe anytime from getting updates from us
Developed and maintained by Wikiance
Developed and maintained by Wikiance