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

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

问题描述

我可以注册任务的输出吗?是否有关于 ansible 命令的参数?

这是我的命令:

<块引用>

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

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

解决方案

在你的 ansible.cfg 中的 [defaults] 组下设置以下内容

<块引用>

bin_ansible_callbacks=True

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

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

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

This is my command:

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?

解决方案

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

bin_ansible_callbacks=True

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天全站免登陆