向Ansible CLI/Ad-Hoc注册变量输出 [英] Register a variable output with Ansible CLI / Ad-Hoc

查看:112
本文介绍了向Ansible CLI/Ad-Hoc注册变量输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以注册任务的输出吗? ansible命令是否为此提供了参数?

Can I register the output of a task? Is there an argument with ansible command for that ?

这是我的命令:

ansible all -m ios_command -a"commands='show run'" -i Resources/Inventory/hosts

我需要这个,因为输出是一本字典,我只需要一个键的值.如果无法做到这一点,是否有办法将该键的值保存到文件中?

I need this, because the output is a dictionary and I only need the value for one key. If this is not possible, is there a way to save the value of that key to a file?

推荐答案

在ansible.cfg中的[默认值]组下设置以下内容

Set the following in your ansible.cfg under the [defaults] group

bin_ansible_callbacks = True

bin_ansible_callbacks=True

然后如@D_Esc所述,您可以使用 ANSIBLE_STDOUT_CALLBACK=json ansible all -m ios_command -a"commands='show run'" -i Resources/Inventory/hosts 并可以获得您可以尝试解析的json输出.

Then as @D_Esc mentioned, you can use ANSIBLE_STDOUT_CALLBACK=json ansible all -m ios_command -a"commands='show run'" -i Resources/Inventory/hosts and can get the json output which you can try to parse.

我还没有找到使用临时命令将输出注册到变量的方法

I have not found a way to register the output to a variable using ad-hoc commands

这篇关于向Ansible CLI/Ad-Hoc注册变量输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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