2

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?

3

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
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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.