在这里,我有一个关于如何使用 Ansible 在结构化文件中查找值的小问题。我看过 lineinfile 但我不太确定它是否会有所帮助。如果我们假设我的文件看起来像这样(实际上它要长得多,但由于明显的原因我不能在这里发布它^^)
################## junos.conf ##################
system {
auto-snapshot;
root-authentication {
encrypted-password ## SECRET-DATA
}
services {
ssh;
netconf ssh;
scp;
}
syslog {
user * {
any emergency;
}
file messages {
any notice;
authorization info;
}
file interactive-commands {
interactive-commands any;
}
}
processes {
dhcp-service {
traceoptions {
file dhcp_logfile size 10m;
level all;
flag all;
}
}
}
}
interfaces {
irb {
unit 0 {
family inet {
dhcp {
vendor-id Juniper-ex4300-48t;
}
}
}
}
vme {
unit 0 {
family inet {
address 172.0.0.1/24
}
}
}
}
forwarding-options {
storm-control-profiles default {
all;
}
}
vlans {
default {
vlan-id 1;
l3-interface irb.0;
}
}
这是一个.conf
文件,但它看起来像一个结构化文件。想象一下,我想找到一种方法来获取interfaces->vme->unit 0->family inet
Ansible 剧本中的价值,我该怎么做?我可以在 Ansible 中使用哪个解析器?
我已经阅读了此页面,但我真的不知道要使用哪个解析器以及如何使用它:https ://docs.ansible.com/ansible/latest/network/user_guide/cli_parsing.html
谢谢,马克斯