如何从 Ansible 中设置模块的输出中获取列表的第一个元素? [英] How to get the first element of a list from the output of setup module in Ansible?
本文介绍了如何从 Ansible 中设置模块的输出中获取列表的第一个元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我从设置模块收到以下数据:
I received the following data from the setup module:
"ansible_nodename": "3d734bc2a391",
"ansible_os_family": "RedHat",
"ansible_pkg_mgr": "yum",
"ansible_processor": [
"AuthenticAMD",
"AMD PRO A10-8700B R6, 10 Compute Cores 4C+6G"
],
"ansible_processor_cores": 1,
"ansible_processor_count": 1,
"ansible_processor_threads_per_core": 1,
我想检索 ansible_processor
的第一个值并在 Jinja2 模板中使用它.
I want to retrieve the 1st value of ansible_processor
and use it in a Jinja2 template.
如果我使用 {{ ansible_processor }}
,它会给我两个值:
If I use {{ ansible_processor }}
, it's giving me both values:
"AuthenticAMD",
"AMD PRO A10-8700B R6, 10 Compute Cores 4C+6G"
但我只想要第一个.
推荐答案
获取列表的第一项:
- debug:
msg: "First item: {{ ansible_processor[0] }}"
或者:
- debug:
msg: "First item: {{ ansible_processor | first }}"
这篇关于如何从 Ansible 中设置模块的输出中获取列表的第一个元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文