Я застрял на задаче, которую пытаюсь использовать with_together и l oop через несколько списков. Вот сценарий: -
У меня есть два набора данных:
"node_list": [
"10.2.0.1",
"10.2.0.2",
]
"java_process_list": [
[
"8612",
"8622",
"8623",
"8625"
],
[
"8613",
"8627",
"8628",
"8630"
]
]
Теперь я хочу, чтобы первый элемент моего node_list, т.е. (10.2.0.1), перебрал все 4 элемента в первом списке process_list т. е. (8612,8622,8623,8625) и т. д.
Что я делаю: -
task1.yml: -
- name: Execute Script to grep IP address of dynamic nodes
command: sh grep_nodes.sh
args:
chdir: "{{ somedir }}"
register: result
- name: set fact
set_fact: dynamic_nodes="{{ item }}"
with_items: "{{ result.stdout_lines}}"
register: items
- name: make a list
set_fact: node_list="{{ items.results | map(attribute='ansible_facts.dynamic_nodes') | list }}"
- debug: var=node_list
- name: Get running java process of dynamic machines
shell: ssh -i /tmp/key.pem {{item}} ps -ef | grep -v grep | grep -w java | grep GSC | awk '{print$2}'
with_items: "{{node_list}}"
register: process
- name: set fact
set_fact: java_process="{{ item.stdout_lines }}"
with_items: "{{process.results}}"
register: items
- name: make a list
set_fact: java_process_list="{{ items.results | map(attribute='ansible_facts.java_process') | list }}"
- debug: var=java_process_list
- name: Print items
shell: 'echo {{item.0}}, echo {{item.1}}'
args:
chdir: "{{maindir}}"
with_together:
- "{{ dynamic_ip_list }}"
- "{{ java_process_list }}"
Когда я запускаю playbook, я получаю следующий вывод: -
{
"_ansible_parsed": true,
"stderr_lines": [],
"cmd": "echo 10.2.0.1, echo 8612",
"stderr": "",
"stdout": "10.2.0.1, echo 8612",
"_ansible_item_result": true,
"attempts": 1,
"delta": "0:00:00.013837",
"stdout_lines": [
"10.2.0.1, echo 8612"
],
"_ansible_no_log": false,
"end": "2020-03-16 12:23:58.704174",
"_ansible_item_label": [
"10.2.0.1",
"8612",
"8622",
"8623",
"8625"
],
"start": "2020-03-16 12:23:58.690337",
"changed": true,
"item": [
"10.2.0.1",
"8612",
"8622",
"8623",
"8625"
],
"rc": 0,
"invocation": {
"module_args": {
"creates": null,
"executable": null,
"_uses_shell": true,
"_raw_params": "echo 10.2.0.1, echo 8612",
"removes": null,
"argv": null,
"warn": true,
"chdir": "/tmp",
"stdin": null
}
},
"_ansible_ignore_errors": null
}
{
"_ansible_parsed": true,
"stderr_lines": [],
"cmd": "echo 10.2.0.2, echo 8613",
"stderr": "",
"stdout": "10.2.0.2, echo 8613",
"_ansible_item_result": true,
"attempts": 1,
"delta": "0:00:00.015971",
"stdout_lines": [
"10.2.0.2, echo 8613"
],
"_ansible_no_log": false,
"end": "2020-03-16 12:23:58.921053",
"_ansible_item_label": [
"10.2.0.2",
"8613",
"8627",
"8628",
"8630"
],
"start": "2020-03-16 12:23:58.905082",
"changed": true,
"item": [
"10.2.0.2",
"8613",
"8627",
"8628",
"8630"
],
"rc": 0,
"invocation": {
"module_args": {
"creates": null,
"executable": null,
"_uses_shell": true,
"_raw_params": "echo 10.2.0.2, echo 8613",
"removes": null,
"argv": null,
"warn": true,
"chdir": "/tmp",
"stdin": null
}
},
"_ansible_ignore_errors": null
}
Ожидаемый результат: -
echo 10.2.0.1, echo 8612
echo 10.2.0.1, echo 8622
echo 10.2.0.1, echo 8623
echo 10.2.0.1, echo 8625
echo 10.2.0.2, echo 8613
echo 10.2.0.2, echo 8627
echo 10.2.0.2, echo 8628
echo 10.2.0.2, echo 8630