ansible
2017-10-18 155 views 0 likes 
0

我有以下變量的清單文件:Ansible:遍歷多個{{項目}}

vpc_public_net1=["10.30.0.0/24","AZ=a"] 
vpc_public_net2=["10.30.1.0/24","AZ=b"] 

我可以"{{ item[1].split('=')[1] }}"

提取AZ值我有兩個提取困難子網並使用相同的 ansible任務​​

我ansible代碼:

- name: Create Public Subnets 
    ec2_vpc_subnet: state="present" 
        vpc_id="{{ vpc_id }}" 
        cidr="{{ item.subnet }}" 
        az="{{ item.az }}" 
        region="{{ aws_region }}" 
        aws_access_key="{{ aws_access_key }}" 
        aws_secret_key="{{ aws_secret_key }} 

回答

0

重新定義爲字典:

vpc_public_net1='{"subnet": "10.30.0.0/24", "az": "a"}' 
vpc_public_net2='{"subnet": "10.30.1.0/24", "az": "b"}' 

和:

- name: Create Public Subnets 
    ec2_vpc_subnet: 
    state: present 
    vpc_id: "{{ vpc_id }}" 
    cidr: "{{ item.subnet }}" 
    az: "{{ item.az }}" 
    region: "{{ aws_region }}" 
    aws_access_key: "{{ aws_access_key }}" 
    aws_secret_key: "{{ aws_secret_key }}" 
    with_items: 
    - "{{ vpc_public_net1 }}" 
    - "{{ vpc_public_net2 }}" 
相關問題