How to get the first list item from the output of the installation module in Ansible?

I got the following data from the settings 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 get the 1st value of ansible_processor and use it in a Jinja2 template.

If I use {{ ansible_processor }} , it gives me both values:

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

But I want only the first.

+7
jinja2 ansible ansible-facts ansible-template
source share
1 answer

To get the first item in a list:

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

Or:

 - debug: msg: "First item: {{ ansible_processor | first }}" 
+12
source share

All Articles