团队, 无法理解或解决此错误。我的任务是从变量中获取服务器名称,并使用dig模块执行dns查找。有什么提示吗?完全相同的任务在本地ubuntu桌面上工作,但是当我通过jenkins / container / ubuntu映像运行它时,它却无法运行。
- name: Validate DNS record lookup for {{ api_server_public_names }}
debug: msg="{{ lookup('dig', '{{ api_server_public_names }}' )}}"
vars:
dns_response: "{{ lookup('dig', '{{ api_server_public_names }}' )}}"
failed_when: not dns_response
TASK [services-pre-install-checks : Validate DNS record lookup for [u'test.customer.com']] ***
Thursday 31 October 2019 22:05:34 +0000 (0:00:00.037) 0:00:02.890 ******
fatal: [localhost]: FAILED! => {"msg": "An unhandled exception occurred while running the lookup plugin 'dig'. Error was a <type 'exceptions.AttributeError'>, original message: 'list' object has no attribute 'startswith'"}
15:05:34
答案 0 :(得分:1)
api_server_public_names
是一个列表,不能直接在查找中使用。您将需要遍历变量:
- name: Validate DNS record lookup
debug: msg="{{ lookup('dig', '{{ item }}' )}}"
vars:
dns_response: "{{ lookup('dig', '{{ item }}' )}}"
failed_when: not dns_response
loop: "{{ api_server_public_names }}"
但是请注意,您的failed_when
无法正常工作。您可能需要执行类似于failed_when: dns_response == "NXDOMAIN"