ansible

handlersのデバッグ

ansibleのhandlerは便利なのですが、想定通り動かない場合にデバッグが難しいです。

サンプル

handlersは、notifyで通知された名前のhandlerを実行します。複数のタスクを実行する方法が分かりません…

handlerでシェルを起動する際、結果はどうあれ、出力を記録したかったのですが…
handlerの2つ目のdebugは、普通に動きませんでした。

$ cat site.yml
---
- hosts: appservers
tasks:
- shell: ls
notify: aaa
handlers:
- name: aaa
shell: ls -l
register: result
- debug: var="result.stdout_lines"
$ ansible-playbook -i hosts site.yml
PLAY ***************************************************************************
TASK [setup] *******************************************************************
ok: [appserv1]
TASK [command] *****************************************************************
changed: [appserv1]
RUNNING HANDLER [aaa] **********************************************************
changed: [appserv1]
PLAY RECAP *********************************************************************
appserv1                   : ok=3    changed=2    unreachable=0    failed=0
$ 

とりあえず…

-vvオプションでとりあえず実効結果は確認できますが、分かりにくい…

$ ansible-playbook -i hosts site.yml -vv
Using /home/vagrant/.ansible.cfg as config file
1 plays in site.yml
PLAY ***************************************************************************
TASK [setup] *******************************************************************
ok: [appserv1]
TASK [command] *****************************************************************
NOTIFIED HANDLER aaa
changed: [appserv1] => {"changed": true, "cmd": "ls", "delta": "0:00:00.001665", "end": "2016-02-27 11:16:25.886746", "rc": 0, "start": "2016-02-27 11:16:25.885081", "stderr": "", "stdout": "git\npub\nwork", "stdout_lines": ["git", "pub", "work"], "warnings": []}
RUNNING HANDLER [aaa] **********************************************************
changed: [appserv1] => {"changed": true, "cmd": "ls -l", "delta": "0:00:00.002075", "end": "2016-02-27 11:16:26.002306", "rc": 0, "start": "2016-02-27 11:16:26.000231", "stderr": "", "stdout": "total 12\ndrwxr-xr-x 5 vagrant vagrant 4096 Feb 25 22:51 git\ndrwxr-xr-x 2 root    root    4096 Sep 26 16:23 pub\ndrwxr-xr-x 4 vagrant vagrant 4096 Feb 17 00:25 work", "stdout_lines": ["total 12", "drwxr-xr-x 5 vagrant vagrant 4096 Feb 25 22:51 git", "drwxr-xr-x 2 root    root    4096 Sep 26 16:23 pub", "drwxr-xr-x 4 vagrant vagrant 4096 Feb 17 00:25 work"], "warnings": []}
PLAY RECAP *********************************************************************
appserv1                   : ok=3    changed=2    unreachable=0    failed=0
$ 
タイトルとURLをコピーしました