Ansible 未定义变量

Ansible undefined variable

我负责 Route53 (http://docs.ansible.com/ansible/route53_module.html),任务是:

- 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"

如果我 运行 支付簿角色失败,因为第二个值具有未定义的故障转移,health_check 和标识符。我如何为 IF else 设置表达式?

我的尝试:

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

无效。我需要 IF not defined THEN IGNORE VALUE.

感谢帮助!

来自docs

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