如何从Ansible的setup模块的输出中获取列表的第一个元素? [英] How to get the first element of a list from the output of setup module in Ansible?

查看:585
本文介绍了如何从Ansible的setup模块的输出中获取列表的第一个元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从设置模块收到了以下数据:

  ansible_nodename: 3d734bc2a391,
ansible_os_family: RedHat,
ansible_pkg_mgr: yum,
ansible_processor:[
AuthenticAMD,
AMD PRO A10-8700B R6,10计算核心4C + 6G
],
ansible_processor_cores:1,
ansible_processor_count:1,
ansible_processor_threads_per_core:1,
ansible_processor
的第一个值,并在Jinja2模板中使用它。



如果我使用 {{ansible_processor}} ,它会给我两个值:

  AuthenticAMD,
AMD PRO A10-8700B R6,10个计算内核4C + 6G

但是我只想要第一个。

解决方案

要获取列表中的第一项:

 -调试:
msg:第一项:{{ansible_processor [0]}}

或:

 -调试:
msg:第一个项目:{{ansible_processor | first}}


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,

I want to retrieve the 1st value of ansible_processor and use it in a Jinja2 template.

If I use {{ ansible_processor }}, it's giving me both values:

"AuthenticAMD",
"AMD PRO A10-8700B R6, 10 Compute Cores 4C+6G"

But I want only the first one.

解决方案

To get first item of the list:

- debug:
    msg: "First item: {{ ansible_processor[0] }}"

Or:

- debug:
    msg: "First item: {{ ansible_processor | first }}"

这篇关于如何从Ansible的setup模块的输出中获取列表的第一个元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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