9
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Ansibleでサーバ一括再起動

Posted at

Ansibleでサーバ一括起動し、SSHログインできるまで待つ

---
# reboot.yml

- name: reboot all hosts and wait it come back in port 22
  hosts: all
  remote_user: ec2-user
  sudo: yes


  tasks:
    - name: hostname
      command: uname -n
      register: hostname
    - debug: msg="{{hostname.stdout_lines}}"

    - name: Restart server
      command: shutdown -r now "Reboot triggered by Ansible"
      async: 0
      poll: 0
      ignore_errors: true
      notify: Wait for server to restart

  handlers:
    - name: Wait for server to restart
      local_action:
        module: wait_for
          host={{ inventory_hostname }}
          port=22
          delay=1
          timeout=300
        #sudo: false

9
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?