tri*_*lef 4 linux shell ansible ansible-playbook
使用 Ansible 我希望能够将运行命令的任务的 sysout 写入本地(即在托管服务器上)日志文件。目前我只能使用这样的任务来做到这一点:
- name: Run my command
shell: <command> <arg1> <arg3> ... |tee -a <local log file>
Run Code Online (Sandbox Code Playgroud)
这样做的原因是需要很长时间才能完成(即我们不能等到它完成才能获取其输出)并且希望在其执行期间收集输出。
是否有任何“Ansible”方法可以在不使用tee
管道的情况下在执行期间将命令的 sysout 重定向到本地日志文件?
您需要在第一个任务中使用 register,现在,您可以创建第二个任务将输出写入本地文件
- name: shell command
shell: my_shell_command
register: myshell_output
- name: copy the output to a local file
copy:
content: "{{ myshell_output.stdout }}"
dest: "/tmp/hello.txt"
delegate_to: localhost
Run Code Online (Sandbox Code Playgroud)