Ansibleのエラー結果、デフォルトだと以下のように1行で表示されて大変読みづらいです。
結論を先に言ってしまうと以下コマンドを実行してからansibleしましょう、という話です。
export ANSIBLE_STDOUT_CALLBACK=yaml
読みづらいエラーの具体例としては以下のような感じ。 改行コードが \n と出ているのがわかります。
TASK [Install chromedriver] *******************************************************************************************************************
******
fatal: [aws-test-analytics]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'dict object' has no at
tribute 'content'\n\nThe error appears to have been in '/home/morihaya/go/src/myrepo/Infrastructure/infra-ansible
/testplay.yml': line 15, column 5, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be
:\n\n\n - name: Install chromedriver\n ^ here\n"}
to retry, use: --limit @/home/morihaya/go/src/myrepo/Infrastructure/infra-ansible/testplay.retry
そこでぼやきました。
terraformのplanが大変見やすくなるlandscapeみたいなの、ansibleにもありませんかね?特にエラーメッセージをいい感じに整形してほしい....
— もりはや (@morihaya55) 2019年1月21日
するとプロからサクッと返答をいただきました。
うおおお!!!見やすいですー><
— もりはや (@morihaya55) 2019年1月21日
ありがとうございます、さすが!!!
で実際に export ANSIBLE_STDOUT_CALLBACK=yaml して全く同じエラーを出すと以下のように!大変読みやすいです。
TASK [Install chromedriver] *******************************************************************************************************************
fatal: [aws-test-analytics]: FAILED! =>
msg: |-
The task includes an option with an undefined variable. The error was: 'dict object' has no attribute 'content'
The error appears to have been in '/home/morihaya/go/src/myrepo/Infrastructure/infra-ansible/testplay.yml': line 15, column 5, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
- name: Install chromedriver
^ here
to retry, use: --limit @/home/morihaya/go/src/myrepo/Infrastructure/infra-ansible/testplay.retry
PLAY RECAP ********
今回の件はAnsibleを雰囲気で使ってたことがよく分かる機会になりましたし、どこかのタイミングでAnsibleオプションをきちっと自分で整理する必要があると思いました。
それ以上に善意のヘルプをしてくれるTwitterやブログなどのWebを通した親切で最高な皆さんに感謝したいという気持ちを新たにしました。(そして自分も誰かの助けになれたらなーという)