我正在尝试使用with_sequence之类的循环遍历子元素变量,
目前我有:
---
- hosts: corosync
gather_facts: no
vars:
host_list:
- node_one
- node_two
list_services:
- group: ALPHA
services:
- name: DHCP
directory: /etc/dhcp
- name: DNS
directory : /etc/dns
- group: BETA
services:
- name: SSH
directory: /etc/ssh
- name: FTP
directory: /ztc/ftp
tasks:
- name: create group-services
debug:
msg: "the service name is {{ item.0.group}}-{{ item.1.name}} , directory is {{ item.1.directory }}"
with_subelements:
- "{{ list_services }}"
- services
因为我的集群中有2个节点
我想取消每种服务,如下所示:
{{ item.0.group}}-{{host_id}}-{{ item.1.name}}
由于我有2个节点,因此{{ host_id }}
的列表等于['0','1']
和with_subelement
函数在{{ host_id }}
上循环两次,因为我们有两个节点,这给出了:
ALPHA-1-DNS
BETA-0-SSH
我想在with_sequence
旁边使用类似with_subelement
的功能
with_sequence: start=0, end={{ groups['host_list']|length}}
请提出任何建议
答案 0 :(得分:2)
loop
declaration introduced in Ansible 2.5非常简单ー您只需要组合两种模式来替换legacy with_sequence
和legacy with_subelements
:
NSToolbarItem