Существует задача ansible с манипуляциями ansible_facts:
- name: "Output facts"
debug:
msg:
CPU_TYPE: "{{ansible_processor|select('match', '.*CPU.*')|list|unique}}"
register: custom_result
Как выбрать строки, содержащие ЦП из этого массива:
"CPU_TYPE": [
"0",
"GenuineIntel",
"Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz",
"1",
"GenuineIntel",
"Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz",
"2",
"GenuineIntel",
"Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz",
"3",
"GenuineIntel",
"Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz",
"4",
"GenuineIntel",
"Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz",
"5",
"GenuineIntel",
"Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz",
"6",
"GenuineIntel",
"Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz",
"7",
"GenuineIntel",
"Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz"
],
В настоящее время я получаю сообщение об ошибке:
"CPU_TYPE": "<generator object select_or_reject at 0x7facb2065930>",
С уважением
UPD:
How to get value from squre brackets:
- name: "Output facts"
debug:
msg:
CPU_TYPE: "{{ansible_processor|select('match', '.*CPU.*')|list|unique}}"
register: custom_result
От этого:
"CPU_TYPE": [
"Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz"
],
До этого:
"CPU_TYPE": "Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz"