小编smo*_*hir的帖子

Ansible With_Together 循环迭代

我陷入了一项任务,我试图使用 with_together 并循环访问多个列表。这是场景:-

我有两组数据:

"node_list": [
"10.2.0.1", 
"10.2.0.2",
]

"java_process_list": [ 
  [
   "8612",
   "8622",
   "8623",
   "8625"
  ], 
  [
   "8613",
   "8627",
   "8628",
   "8630"
  ] 
]
Run Code Online (Sandbox Code Playgroud)

现在我希望我的node_list的第一个项目即(10.2.0.1)迭代process_list的第一个列表中的所有4个项目即(8612,8622,8623,8625)等等。

我正在做的是:-

任务1.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 …
Run Code Online (Sandbox Code Playgroud)

ansible ansible-2.x ansible-facts

2
推荐指数
1
解决办法
4236
查看次数

标签 统计

ansible ×1

ansible-2.x ×1

ansible-facts ×1