2016-11-11 85 views
0

我有Route53角色(http://docs.ansible.com/ansible/route53_module.html)和任務是:Ansible未定義可變

- name: "SET DNS record" 
    route53: 
    aws_access_key: "ACCESSKEY" 
    aws_secret_key: "SECRET" 
    command: "create" 
    zone: "{{ dns_zone }}" 
    hosted_zone_id: "{{ dns_zone_id }}" 
    record: "{{ item.dns_record }}" 
    type: "{{ item.dns_type }}" 
    ttl: "{{ item.dns_ttl }}" 
    value: "{{ item.dns_value }}" 
    failover: "{{item.failover}}" 
    health_check: "{{item.health_check}}" 
    identifier: "{{item.identifier}}" 
    with_items: 
    - "{{ dns_records }}" 

的DNS記錄示例:

dns_records: 
    - dns_record: "try1.example.com" 
    dns_type: "A" 
    dns_ttl: "3600" 
    dns_value: "1.1.1.1" 
    failover: "PRIMARY" 
    health_check: "aeejas728asd" 
    identifier: "identifier01" 
    - dns_record: "try2.example.com" 
    dns_type: "A" 
    dns_ttl: "3600" 
    dns_value: "2.2.2.2" 

如果用完paybook作用失敗,因爲第二值具有未定義的故障轉移, health_check和標識符。我如何設置表達式,如果其他?

我嘗試:

identifier: "{{item.identifier if item.identifier is defined else '!'}}" 

不工作。我需要IF沒有定義然後忽略價值。

感謝您的幫助!

回答

1

docs

identifier: "{{item.identifier|default(omit)}}" 
+0

非常感謝!我絕對失明。 – user2918879