Technology Security Analyst
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.
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.
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.
Given beneath are the bring values back:
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.
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:
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:
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:
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.