我试图找到一种方法来存储在Ansible中运行的NSLOOKUP命令的内容,以查找与应用程序关联的CNAME。 CNAME随应用程序的不同而相应地更改。
我在shell中执行了 nslookup 并注册了输出。
- name: Shell Command to perform NSLOOKUP
shell: nslookup abc.xyz.com
register: result
- debug: var=result
NSLOOKUP的输出:
"stdout_lines": [
"Server:\t\t10.10.10.10",
"Address:\t10.10.10.11#53",
"",
"abc.xyz.com\tcanonical name = abc.web.xyz.com.",
"Name:\tabc.web.xyz.com",
"Address: 10.210.120.111"
]
基本上,我需要获取Name值的输出,该值在应用程序之间动态变化。所以我不能使用stdout_lines [5],这不适用于每种情况。
答案 0 :(得分:0)
下面的任务报告名称的值(s)
- debug:
msg: "{{ item.split('\t').1 }}"
loop: "{{ result.stdout_lines }}"
when: item is match('^Name:*')
,下一个任务将创建名称(s')值(s)
的列表- set_fact:
names: "{{ names|default([]) + [ item.split('\t').1 ] }}"
loop: "{{ result.stdout_lines }}"
when: item is match('^Name:*')
- debug:
var: names
首选选项应为Ansible本机dig – query DNS using the dnspython library。