Site icon UnixArena

Ansible reboot module – Shutdown Command Not found on Linux

Ansible Reboot module

Ansible is a widely used configuration management tool. Opensource community and RedHat aggressively developing to create modules for each task. In Ansible 2.7, reboot module is responsible to reboot the host and wait to come back. But the Linux image development varies for each organization. In some environment, engineers might remove shutdown command from the command search path or keeping shutdown binary in the custom path. If you bring those machines in Ansible automation, reboot module will fail with error ” shutdown command not found” This article will walk you through how to resolve that issue.

 

Environment:

 

1. Login to Ansible server.

 

2. Here is the reboot ansible playbook.

---
- hosts: all
  become: yes

  tasks:
   - name: Check the uptime
     shell: uptime
     register: UPTIME_PRE_REBOOT

   - debug: msg={{UPTIME_PRE_REBOOT.stdout}}

   - name: Unconditionally reboot the machine with all defaults
     reboot:

   - name: Check the uptime after reboot
     shell: uptime
     register: UPTIME_POST_REBOOT

   - debug: msg={{UPTIME_POST_REBOOT.stdout}}

 

If you get shut down command not found, you have the following options.

 

If you are running with Ansible engine 2.8, then tweak the playbook like below.

 

3. In Ansible 2.8, Ansible’s reboot module had the option to include the command search path as argument. In my hosts, shutdown command has been kept in /usr/sbin/custom/

---
- hosts: all
  become: yes

  tasks:
   - name: Check the uptime
     shell: uptime
     register: UPTIME_PRE_REBOOT

   - debug: msg={{UPTIME_PRE_REBOOT.stdout}}

   - name: Unconditionally reboot the machine with all defaults
     reboot:
         search_paths: /usr/sbin/custom/

   - name: Check the uptime after reboot
     shell: uptime
     register: UPTIME_POST_REBOOT

   - debug: msg={{UPTIME_POST_REBOOT.stdout}}

 

The search_path argument is responsible provide the shutdown command path for reboot module. Try the playbook in the test environment and validate the results.

 

Share it! Comment it!! Be Sociable

Exit mobile version