1
2

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.

Tips: Ansibleのtask name:に時刻を入れる

Posted at

Ansibleのtask実行時刻をログに残す方法例

例1: task name:に時刻を入れる

tasks
- name: '{{ lookup(''pipe'', ''date "+%Y/%m/%d %H:%M:%S"'') }}  debug: { msg: hello world! }'
  debug:
     msg: hello world!

output
TASK [2020/03/11 15:43:39  debug: { msg: hello world! }] ***************************
ok: [localhost] => {
    "msg": "hello world!"
}
  • 出力がコンパクトで済ませれられる
  • ansible コントローラーにおける日時
  • フォーマットは自由
  • ansible-playbookコマンドの--start-at-taskオプションが実質使用できない

例2: ansible.cfgにてcallbackプラグインとしてprofile_tasksを指定する

ansible.cfg
[defaults]
callback_whitelist = profile_tasks
tasks
- name: 'debug: { msg: hello world! }'
  debug:
    msg: hello world!
output
...
TASK [debug: { msg: hello world! }] ***********************************************
Wednesday 11 March 2020  16:19:40 +0900 (0:00:00.054)       0:00:00.054 ******* 
ok: [localhost] => {
    "msg": "hello world!"
}
...
Wednesday 11 March 2020  16:19:40 +0900 (0:00:00.033)       0:00:00.087 ******* 
=============================================================================== 
debug: { msg: hello world! } ----------------------------------------------- 0.03s

例3 debugモジュールで出力

tasks
  - debug:
      msg: '{{ lookup(''pipe'', ''date "+%Y/%m/%d %H:%M:%S"'') }}'
output
TASK [debug] **********************************************************************
ok: [localhost] => {
    "msg": "2020/03/11 16:33:36"
}
  • オーソドックス
  • ansible コントローラーにおける日時
  • フォーマットは自由
  • 出力がコンパクトでは無い
1
2
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
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?