2
1

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によるrebootは、rebootモジュールが使用可能

Last updated at Posted at 2020-03-10

Ansible rebootモジュールを使用する例 (New in version 2.7)

tasks
- reboot:                   # rebootする

- shell: cat /etc/motd
  register: r
- debug:
    var: r.stdout_lines

公式: reboot – Reboot a machine

TASK [reboot] ******************************************************************************************************************
Friday 13 March 2020  14:42:11 +0900 (0:00:00.126)       0:00:00.126 ********** 
changed: [52.117.38.34]

TASK [shell] *******************************************************************************************************************
Friday 13 March 2020  14:44:47 +0900 (0:02:35.306)       0:02:35.432 ********** 
changed: [52.117.38.34]

TASK [debug] *******************************************************************************************************************
Friday 13 March 2020  14:44:51 +0900 (0:00:04.045)       0:02:39.478 ********** 
ok: [52.117.38.34] => {
    "r.stdout_lines": [
        "*******************************************************************************",
        "*                                                                             *",
        "*                                                                             *",
        "*  Welcome to AIX Version 7.2!                                                *",
        "*                                                                             *",
        "*                                                                             *",
        "*  Please see the README file in /usr/lpp/bos for information pertinent to    *",
        "*  this release of the AIX Operating System.                                  *",
        "*                                                                             *",
        "*                                                                             *",
        "*******************************************************************************"
    ]
}

...

=============================================================================== 
reboot ---------------------------------------------------------------------------------------------------------------- 155.31s
shell ------------------------------------------------------------------------------------------------------------------- 4.05s
debug ------------------------------------------------------------------------------------------------------------------- 0.90s

時刻表示の為にansible.cfgの[defaults]にcallback_whitelist = profile_tasksを記載。
自動で再接続まで待ってくれる。

shutdownとwait_for_connectionによる例

tasks
- name: shutdown -Fr &
  shell: shutdown -Fr &     # reboot
  poll: 0                   # 非同期ですぐに次のタスクに進む

- wait_for_connection:      # 接続の回復を待つ
    delay: 30         # ポーリングを開始する前に待機する秒数

- name: cat /etc/motd
  shell: cat /etc/motd
  register: r
- debug:
    var: r.stdout_lines

後続処理を行う為には、wait_for_connectionにて接続回復を待つ必要がある。

TASK [shutdown -Fr &] **********************************************************************************************************
Friday 13 March 2020  15:15:58 +0900 (0:00:00.080)       0:00:00.080 ********** 
changed: [52.117.38.34]

TASK [wait_for_connection] *****************************************************************************************************
Friday 13 March 2020  15:16:05 +0900 (0:00:07.170)       0:00:07.251 ********** 
ok: [52.117.38.34]

TASK [cat /etc/motd] ***********************************************************************************************************
Friday 13 March 2020  15:18:15 +0900 (0:02:09.771)       0:02:17.022 ********** 
changed: [52.117.38.34]

TASK [debug] *******************************************************************************************************************
Friday 13 March 2020  15:18:18 +0900 (0:00:03.191)       0:02:20.214 ********** 
ok: [52.117.38.34] => {
    "r.stdout_lines": [
        "*******************************************************************************",
        "*                                                                             *",
        "*                                                                             *",
        "*  Welcome to AIX Version 7.2!                                                *",
        "*                                                                             *",
        "*                                                                             *",
        "*  Please see the README file in /usr/lpp/bos for information pertinent to    *",
        "*  this release of the AIX Operating System.                                  *",
        "*                                                                             *",
        "*                                                                             *",
        "*******************************************************************************"
    ]
}

...

=============================================================================== 
wait_for_connection --------------------------------------------------------------------------------------------------- 129.77s
shutdown -Fr & ---------------------------------------------------------------------------------------------------------- 7.17s
cat /etc/motd ----------------------------------------------------------------------------------------------------------- 3.19s
debug ------------------------------------------------------------------------------------------------------------------- 0.90s
2
1
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
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?