Ansibleによるrebootは、rebootモジュールが使用可能
Ansible rebootモジュールを使用する例 (New in version 2.7)
tasks
- reboot: # rebootする
- shell: cat /etc/motd
register: r
- debug:
var: r.stdout_lines
tasks
- reboot: # rebootする
- shell: cat /etc/motd
register: r
- debug:
var: r.stdout_lines
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
Author And Source
この問題について(Ansibleによるrebootは、rebootモジュールが使用可能), 我々は、より多くの情報をここで見つけました https://qiita.com/hiroyuki_onodera/items/1adc0dc5481b9f2a6f0c著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .