Linux Tutorials

Ansible reboot Linux machine or server with playbooks

SEOClerks

I have to reboot the VM or naked steel Linux machine/server utilizing Ansible and look ahead to it to return again, but it surely doesn’t work with playbook as descried right here. Learn how to reboot Linux server with Ansible? How do I reboot and look ahead to reboot to finish in Ansible playbook for a number of Linux servers?

Introduction: You’ll be able to reboot a Linux or Unix based mostly machine, look ahead to it to go down (say for kernel replace), come again up, and reply to instructions. You need to use both command or shell module to reboot the Linux server when kernel up to date. Nevertheless, now we’ve a reboot module to reboot a machine utilizing Ansible. I examined this module with: Ubuntu Linux 16.04 / 18.04 LTSCentOS Linux 7Debian Linux 9.xRHEL 7.xSUSE 12.xFreeBSDOpenBSD

Prerequisite

Please observe that you will need to have Ansible model 2.7 to work with the reboot module:
$ ansible –version
Linux find out ansible version command
If not utilizing Ansible model 2.7, attempt to replace it utilizing the dnf command/yum command/apt command/apt-get command as per your Linux distro model:
$ sudo apt replace ## Debian or Ubuntu field ##
$ sudo yum replace ## RHEL/CentOS 7 ##

Ansible reboot Linux machine or server with playbooks

The syntax is fairly easy to do reboot:

– title: Reboot the machine with all defaults utilizing Ansible
reboot:

Here’s a pattern hosts file displayed utilizing the cat command:

[all:vars]
k_ver=“linux-image-Four.15.Zero-36-generic”
ansible_user=
ansible_become=sure
ansible_become_method=sudo
ansible_become_pass=
 
[legacy]
do-de.public
 
[cluster]
ln.cbz01
ln.cbz02
ln.cbz04
ln.discussion board
 
[lxd]
ln.cbz01
ln.cbz02
ln.cbz04
do-de.public
 
[vpn:vars]
ansible_python_interpreter=‘/usr/bin/env python3’
 
[vpn]
do-blr-vpn
 
[backup]
gcvm.backup
 
[nodes:kids]
vpn
backup
cluster
legacy
 
[isrestart:kids]
backup
cluster
vpn

Right here is my reboot.yml:


– hosts: isrestart
grow to be: true
become_user: root
duties:
– title: Rebooting the cloud server/naked steel field
reboot:

Learn how to use Ansible reboot module playbook to reboot the field

Now all you need to do is run playbook (see tips on how to set and use sudo password for Ansible Vault)
$ ansible-playbook -i hosts –ask-vault-pass –extra-vars ‘@cluster.knowledge.yml’ reboot.yml
Ansible reboot Linux machine or server with playbooks commands

Learn how to reboot a machine and set day out worth

By default Ansible reboot module waits 600 seconds. You’ll be able to enhance worth utilizing the next syntax:

– title: Reboot a Linux machine
reboot:
reboot_timeout: 1800

Learn how to set command to run on the rebooted host and count on success from to find out the machine is prepared for additional duties

By default whoami command utilized by ansbile. You’ll be able to change it as follows:

– title: Reboot a Linux machine
reboot:
test_command: uptime

OR

– title: Reboot a Linux machine
reboot:
test_command: ping -c Four 192.168.2.254

Learn how to set pre and submit reboot delay

One can drive Ansible to attend after the reboot was profitable and the connection was re-established in seconds as follows:

– title: Unconditionally reboot the machine with all defaults
reboot:
post_reboot_delay: 180

The above is helpful if you’d like wait for extra networking/storage or server vpn to kick in regardless of your connection already working. You can even set time for shutdown to attend earlier than requesting reboot:

– title: Unconditionally reboot the machine with all defaults
reboot:
pre_reboot_delay: 180

Conclusion

You simply realized tips on how to reboot Linux/Unix field and look ahead to reboot to finish in Ansible playbook. For more information see this web page right here.

Posted by: Vivek Gite

The writer is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a coach for the Linux working system/Unix shell scripting. Get the newest tutorials on SysAdmin, Linux/Unix and open supply subjects by way of RSS/XML feed or weekly electronic mail publication.

Source link

Related Articles

Leave a Reply

Back to top button