Ansible-将注册变量保存到文件 [英] Ansible - Save registered variable to file

查看:182
本文介绍了Ansible-将注册变量保存到文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将已注册的变量保存到文件中?我是从教程中获得的:

How would I save a registered Variable to a file? I took this from the tutorial:

- 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变量保存到文件中,例如foo_result.log使用ansible?

How would I save foo_result variable to a file e.g. foo_result.log using ansible?

推荐答案

您可以使用带有参数content=copy模块.

You can use the copy module, with the parameter content=.

我在这里给出了完全相同的答案:将变量写入Ansible中的文件

I gave the exact same answer here: Write variable to a file in Ansible

在您的情况下,您似乎希望将此变量写入本地日志文件,因此可以将其与local_action表示法组合:

In your case, it looks like you want this variable written to a local logfile, so you could combine it with the local_action notation:

- local_action: copy content={{ foo_result }} dest=/path/to/destination/file

这篇关于Ansible-将注册变量保存到文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆