Key Weirdness with Dict Return Result from Lookup and Dig

Delving deeper into ansible and its has been fun (will be honest, some parts of it feel tortured as you try to get more programmatic about it. and i know that’s my issue! lol. But really nice to get up and going).

For example, while I am sure there is an easier way to do the below (waiting on a DNS update before proceeding, feel free to suggest!) I was really surprised that I had to use the command as the key here.

Is there a cleaner way to use the lookup and verify the IP in the result is my question really (with a secondary hope that there is a better way than raw output from nslookup or ?? There has to be a pattern I haven’t found.)

Thanks

    - name: Wait for Google DNS to Update
      debug:
        var: lookup('dig', '{{ fqdn }}', '@8.8.8.8')
      register: test_var
      until: new_ip == test_var["lookup('dig', '{{ fqdn }}', '@8.8.8.8')"]
#       new_ip in test_var doesn't work
#      retries: 12
#      delay: 5
    - name: and test_var is?
      debug:
        msg: "{{ test_var }}"

Here is the output:

ok: [localhost] => {
    "msg": {
        "changed": false,
        "failed": false,
        "lookup('dig', 'test.com', '@8.8.8.8')": "192.138.219.231")
    }
}

And thought that maybe query would get me the desired result. Though easier for multiple IPs to work with, still the same key ugliness…

ok: [localhost] => {
    "msg": {
        "changed": false,
        "failed": false,
        "query ('dig', 'yahoo.com', '@8.8.8.8')": [
            "98.137.246.7",
            "98.138.219.231",
            "98.137.246.8",
            "72.30.35.10",
            "98.138.219.232",
            "72.30.35.9"
        ]
    }
}

Go to Source
Author: IGotAHeadache