<p><a href="https://docs.ansible.com/ansible/latest/modules/reboot_module.html" rel="nofollow noreferrer">https://docs.ansible.com/ansible/latest/modules/reboot_module.html</a></p>

<blockquote>
<pre><code>- name: Unconditionally reboot the machine with all defaults
  reboot:

- name: Reboot a slow machine that might have lots of updates to apply
  reboot:
    reboot_timeout: 3600
</code></pre>
</blockquote>

CC BY-SA 4.0
2019-07-27T09:24:44.550Z
2019-07-27T09:24:44.550Z
030
<p>Use this source code for reboot your client machine</p>

<pre><code>---
  - name: System Reboot
    hosts: debian
    become_method: sudo
    become_user: root
    become: true
    tasks:
      - name: reboot nodes     # Reboot client side debian machine 
        shell: sleep 2 &amp;&amp; shutdown -r now "Ansible reboot"
        async: 1
        poll: 0
        ignore_errors: true
      - name: wait for the server to come back  # when server timeout it through error. That error is handle by ignore_errors.
        local_action: wait_for
        args:
          host: "{{ inventory_hostname }}"
          port: 22
          state: started
          delay: 120
          timeout: 200
        ignore_errors: true
</code></pre>

CC BY-SA 4.0
2019-10-18T07:42:57.540Z
2019-10-18T07:42:57.540Z
Shaha Nawaj Mulla
<p>I have 3 scripts that must be run on server one by one. for example:  </p>

<pre><code>- name: find config
  shell: /data/scripts/config1
  become: yes
  become_user: root
  tags: find_config

- name: change config
  shell: /data/scripts/config2
  become: yes
  become_user: root
  tags: change_config

- name: confirm config
  shell: /data/scripts/config3
  become: yes
  become_user: dbusr1
  tags: confirm_config
</code></pre>

<p>in second script <code>config2</code> there is a reboot command and then the rest of script will be run at start up. something like this:  </p>

<pre><code>some variables
.
.
commands before reboot
.
.
reboot command
.
.
commands that run at start up
</code></pre>

<p>does this reboot affect ansible tasks? how i can write tasks that wait until <code>commands that run at start up</code> be run then execute <code>config3</code>? is this even possible in ansible? what modules should i use?</p>

<ansible><linux><centos>
reboot server during Ansible tasks
BlackCrystal
# reboot server during Ansible tasks

(Asked by: username_0 on 2019-07-27)

I have 3 scripts that must be run on server one by one. for example:  
- name: find config
  shell: /data/scripts/config1
  become: yes
  become_user: root
  tags: find_config

- name: change config
  shell: /data/scripts/config2
  become: yes
  become_user: root
  tags: change_config

- name: confirm config
  shell: /data/scripts/config3
  become: yes
  become_user: dbusr1
  tags: confirm_config

in second script config2 there is a reboot command and then the rest of script will be run at start up. something like this:  
some variables
.
.
commands before reboot
.
.
reboot command
.
.
commands that run at start up

does this reboot affect ansible tasks? how i can write tasks that wait until commands that run at start up be run then execute config3? is this even possible in ansible? what modules should i use?

**Tags:** ansible, linux, centos


---

## 2 answers

### Answer by username_2 on 2019-10-18. Score: 4 | Accepted answer

Use this source code for reboot your client machine
---
  - name: System Reboot
    hosts: debian
    become_method: sudo
    become_user: root
    become: true
    tasks:
      - name: reboot nodes     # Reboot client side debian machine 
        shell: sleep 2 && shutdown -r now "Ansible reboot"
        async: 1
        poll: 0
        ignore_errors: true
      - name: wait for the server to come back  # when server timeout it through error. That error is handle by ignore_errors.
        local_action: wait_for
        args:
          host: "{{ inventory_hostname }}"
          port: 22
          state: started
          delay: 120
          timeout: 200
        ignore_errors: true


---

### Answer by username_1 on 2019-07-27. Score: 3

https://docs.ansible.com/ansible/latest/modules/reboot_module.html

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

- name: Reboot a slow machine that might have lots of updates to apply
  reboot:
    reboot_timeout: 3600


---

