我在 ansible 中收到了以下格式的调试消息:
"msg": [
"Output: test output ",
"ABC: some text ",
"",
"Master ",
"Location: test location ",
"URL: https://www.google.com "
]
}
现在我想从上面的输出中检索 URL 值,我将在其余的 ansible 脚本中使用它。我怎样才能以这种精确的格式获取这个 URL“http://www.google.com”?请帮忙。
答案1
问:“我怎样才能以这种精确的格式获取“http://www.google.com”这个 URL?“
答:创建一个字典。给定列表
my_list:
["Output: test output ",
"ABC: some text ",
"",
"Master ",
"Location: test location ",
"URL: https://www.google.com "]
任务
- set_fact:
my_dict: "{{ my_dict|default({})|combine(item|from_yaml) }}"
loop: "{{ my_list }}"
when: item|from_yaml is mapping
创建字典
my_dict:
ABC: some text
Location: test location
Output: test output
URL: https://www.google.com
获取属性网址
- debug:
var: my_dict.URL
给出
my_dict.URL: https://www.google.com