How to get the first element of a list from the output of setup module in Ansible?

天大地大妈咪最大 提交于 2019-11-27 05:23:50

To get first item of the list:

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

Or:

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

Try this for common handle this situation:

Ref: get-first-n-elements-of-a-list-in-jinja2-template-in-ansible

# from list
- debug:
    msg: "First item: {{ ansible_processor[0] }}"
# from output, like 'https://xxx.xx/xxx/xxx.git'
- debug:
    msg: "git repo's name: {{ (item| urlsplit('path')| basename | splitext)[0] }}"
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!