0

I'm trying to match this output from ansible ping module output:

srv1 | SUCCESS => {
    "changed": false,
    "ping": "pong"
}
srv2 | SUCCESS => {
    "changed": false,
    "ping": "pong"
}

as well as this output from ansible setup module output:

srv1 | SUCCESS => {
"ansible_facts": {
    "ansible_all_ipv4_addresses": [
        "192.168.50.100"
    ],
    "ansible_all_ipv6_addresses": [
        "fe80::a00:27ff:fead:7504"
    ],
    "ansible_apparmor": {
        "status": "disabled"
    },
    "ansible_architecture": "x86_64",
...a lot of lines
}
srv2 | SUCCESS => {
"ansible_facts": {
    "ansible_all_ipv4_addresses": [
        "192.168.51.101"
    ],
    "ansible_all_ipv6_addresses": [
        "fe80::a00:27ff:fe98:b137"
    ],
    "ansible_apparmor": {
        "status": "disabled"
    },
    "ansible_architecture": "x86_64",
...a lot of lines
}

I'd like to put everything between { .. } for specific host into matched variable, so later I can it using yaml.load.

I tried:

regex = r'(\w+)\s\|\s(\w+)\s=>\s(\{\n\s+"\w+":\s\w+,\n\s+"\w+":\s"\w+"\n\})'
o = re.findall(regex,output,re.MULTILINE)
for host in o:
    yml = yaml.load(host[2])

This works for first output, but not for second. So I tried to generalize it:

regex = r'(\w+)\s\|\s(\w+)\s=>\s(\{.*\})'
o = re.findall(regex,output,re.DOTALL)
for host in o:
    yml = yaml.load(host[2])

But this will match everything between starting { and last }.

What am I doing wrong?

Thanx for help

Sigi
  • 43
  • 5

0 Answers0