You are reading the article How Does Ansible Reboot Work updated in September 2023 on the website Chivangcangda.com. We hope that the information we have shared is helpful to you. If you find the content interesting and meaningful, please share it with your friends and continue to follow and support us for the latest updates. Suggested October 2023 How Does Ansible Reboot Work
Introduction to Ansible RebootAnsible provides a plenty of modules which are direct replacement of our Unix/Linux commands, but can work in better way than using those similar commands in scripts. One such module is Ansible reboot module. This module is a replacement of reboot command on Linux/Unix systems but can work in better way. This means, we can reboot the remote target machines with some checks and additional delays pre and post reboot. For Microsoft Windows environments, we have similar module named as win_reboot.
Start Your Free Software Development Course
Web development, programming languages, Software testing & others
What is Ansible Reboot? How does Ansible Reboot work?Like any other Ansible Module, Ansible reboot module is equipped with a set of parameters and acceptable values. Some of these parameters have default values which will be realized to your playbook even if you do not mention the related parameter in playbook. So these become more important to know.
Given below is a list of all available parameters and related acceptable or default values.
test_command: This parameter is used to give the command on rebooted hosts after reboot task and expect success to confirm whether the machine is ready for next tasks in playbook. Default command is “whoami”.
search_paths: This is to give the locations to search for shutdown command on remote target machines. When this is used then PATH environment variable will be Default is /sbin, /usr/sbin and /local/usr/sbin.
reboot_timeout: This time is in seconds and to specify the time to wait for the machine to reboot and respond to a test command. This will be evaluated separately for verification and test command success. Which means maximum amount of time for execution is twice of this value. By default it is set to 600 seconds.
pre_reboot_delay: Time to wait before reboot, this will be set as parameter to reboot On *nix based machines, this is calculated on minutes basis, means seconds converted to minutes and rounded down. If less than 1 minute then it takes as 0. Default is 0.
post_reboot_delay: This is time in seconds to wait, after reboot. Before attempting to validate the system reboot. This is useful if you want to settle down something after reboot. Default is 0.
connect_timeout: The amount of time in seconds to wait for successful connection after reboot, before trying again.
msg: Default message is “Reboot Initiated by Ansible”. This is to specify the message to display to working users before rebooting.
Given below are the return values:
elapsed: The time elapsed waiting for reboot.
rebooted: True if the machine was successfully rebooted.
Examples of Ansible RebootGiven below are the examples mentioned:
Here we have one Ansible controller node named as ansible-controller. As target nodes, we have two remote machines. First machine is a Red Hat Enterprise Linux machine named as host-one and second machine is an Ubuntu machine named as host-two. We will run our playbooks on Ansible controller machine and make changes on remote target machines.
Example #1In this example, we have a playbook like below where we are simply rebooting the target machines.
Code:
– 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 reboot was successful.
ansible-playbook --syntax-check ansible_reboot.yaml
Example #2In this example, we have a playbook like below where we are rebooting the target machines with some pre and post delay and then have a command to test the server is up and ready for next tasks. Here we have used test command as “uptime” instead of default “whoami”.
Code:
-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 test command.
Example #3Code:
-name: Here we are checking the time on remote machines after shell: “ls -l chúng tôi 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:
ConclusionAs we saw in this article, Ansible Reboot is a module which you will need, for sure, in your daily administration or change management tasks. This module provides you ability to work with reboots smartly. But as this module will reboot the remote machines which can lead to downtime or outage. So you must only use this in planned activities. So learn it first and then use it.
Recommended ArticlesThis is a guide to Ansible Reboot. Here we discuss what is ansible reboot? how does ansible reboot work? and examples. You may also have a look at the following articles to learn more –
You're reading How Does Ansible Reboot Work
Update the detailed information about How Does Ansible Reboot Work on the Chivangcangda.com website. We hope the article's content will meet your needs, and we will regularly update the information to provide you with the fastest and most accurate information. Have a great day!