0
我想从github下载密钥并创建aws密钥对。目前我正在使用这些任务。Ansible嵌套循环 - 如何遍历循环项目?
- name: download keys from github
get_url:
url: "https://github.com/{{ item }}.keys"
dest: "/tmp/{{ item }}"
with_items:
- foo
- bar
- name: create ec2 keys
ec2_key: name=foo key_material="{{ item }}" state=present
with_lines: cat /tmp/foo
- name: create ec2 keys
ec2_key: name=bar
with_lines: cat /tmp/bar
但是,这不是干燥的。如何实现这样的事情?
- name: create ec2 keys
ec2_key: name=foo key_material="{{ line }}" state=present
with_lines: cat /tmp/{{item}}
with_items:
- foo
- bar
你会如何命名它们添加所有的钥匙? –
添加示例与多个键 –
[这里](https://docs.ansible.com/ansible/playbooks_loops.html#looping-over-a-list-with-an-index),结合知识_“循环实际上是+ lookup()的组合,因此任何查找插件都可以用作循环的源代码,'items'正在查找。“_。 –