【发布时间】:2019-05-07 21:16:54
【问题描述】:
我正在自动化 F5 BIG IP 配置停用。我需要从执行的任意 bigip 命令中获取池名称。我已将输出的内容存储到寄存器中,并希望获取池名称并将其存储在列表中。
直到从执行命令的输出中获得宽ip信息(包含池名称)为止。
预期输出:-
我可以使用任何正则表达式来获取池信息吗,据我所知,我可以做一个点走来从 JSON 中获取确切的内容。我很确定当有多个池名称时输出不会相同。如果还有多个池,逻辑是什么?
---
- name: Playbook to verify the Wideip and fetch the GTM configuration
hosts: test-gtm.com
connection: local
gather_facts: no
tasks:
- name: Verify WideIP Exists
bigip_command:
user: admin
password: admin
commands: "list gtm wideip a wideip"
validate_certs: no
register: output
delegate_to: localhost
- debug:
var: output
- name: Fetch the Pool name from the WideIP
set_fact:
gtm_pool: "{{ output.stdout_lines[0][1].split()[0] }}"
``
Output without the dot walk :-
"stdout_lines": [
[
"gtm wideip a test.abc.com {",
" pools {",
" test-pool {",
" order 0",
" }",
" }",
"}"
]
Whole debug output :-
"output": {
"changed": false,
"deprecations": [
{
"msg": "Param 'server' is deprecated. See the module docs for more information",
"version": 2.9
},
{
"msg": "Param 'user' is deprecated. See the module docs for more information",
"version": 2.9
},
{
"msg": "Param 'password' is deprecated. See the module docs for more information",
"version": 2.9
},
{
"msg": "Param 'validate_certs' is deprecated. See the module docs for more information",
"version": 2.9
}
],
"executed_commands": [
"tmsh -c \\\"list gtm wideip a wideip\\\""
],
"failed": false,
"stdout": [
"gtm wideip a wideip {\n pools {\n test-pool {\n order 0\n }\n }\n}"
],
"stdout_lines": [
[
"gtm wideip a wideip {",
" pools {",
" test-pool {",
" order 0",
" }",
" }",
"}"
]
]
}
}
Debug output consisting of more than single pool:-
ok: [device.abc.com] => {
"output": {
"changed": false,
"deprecations": [
{
"msg": "Param 'server' is deprecated. See the module docs for more information",
"version": 2.9
},
{
"msg": "Param 'user' is deprecated. See the module docs for more information",
"version": 2.9
},
{
"msg": "Param 'password' is deprecated. See the module docs for more information",
"version": 2.9
},
{
"msg": "Param 'validate_certs' is deprecated. See the module docs for more information",
"version": 2.9
}
],
"executed_commands": [
"tmsh -c \\\"list gtm wideip a wideip\\\""
],
"failed": false,
"stdout": [
"gtm wideip a wideip {\n description wideip\n pool-lb-mode topology\n pools {\n test1-pool {\n order 1\n }\n test2-pool {\n order 0\n }\n }\n}"
],
"stdout_lines": [
[
"gtm wideip a wideip {",
" description wideip",
" pool-lb-mode topology",
" pools {",
" test1-pool {",
" order 1",
" }",
" test2-pool {",
" order 0",
" }",
" }",
"}"
]
]
【问题讨论】:
-
您好,欢迎来到 SO。您的问题缺少主要元素。请参阅stackoverflow.com/help/how-to-ask。更准确地说:你的比赛结果是什么(抱歉,我们无法猜测)?你期待什么?您尝试过什么来实现您的目标,什么没有按预期工作(带有详细信息和错误消息)? ...
-
@Harsha Nalore 至少发布 "-debug: var=output" 的输出。请关注:How to create a Minimal, Complete, and Verifiable example.
-
@VladimirBotka:我已经粘贴了 stdout_lines 的输出,谢谢!
-
@Harsha Nalore 查看答案。这是你所期望的吗?如果没有将您的期望放入问题中。
-
您在此处显示的输出不是该
debug语句的完整输出。您能否显示更多输出,包括结果中的多个池?
标签: ansible