登録した変数をファイルに保存するにはどうすればいいでしょうか?これはチュートリアル:
- hosts: web_servers
tasks:
- shell: /usr/bin/foo
register: foo_result
ignore_errors: True
- shell: /usr/bin/bar
when: foo_result.rc == 5
foo_result
たとえば、ansible を使用して変数をファイルに保存するにはどうすればよいですかfoo_result.log
?
ベストアンサー1
感謝トモショウ古くなった承認済みの回答にこのコメントを追加していただきありがとうございます。
As of Ansible 2.10, The documentation for ansible.builtin.copy says:
If you need variable interpolation in copied files, use the
ansible.builtin.template module. Using a variable in the content field will
result in unpredictable output.
元の回答:
copy
パラメータ を指定してモジュールを使用できますcontent=
。
私はここで全く同じ答えをしました:Ansibleでファイルに変数を書き込む
あなたの場合、この変数をローカル ログ ファイルに書き込む必要があるようなので、次のlocal_action
表記法と組み合わせることができます。
- local_action: copy content={{ foo_result }} dest=/path/to/destination/file