title: Ansible Dynamic Variables in Playbook
body: <p>I'm provisioning a bunch of systems (VMs) on a physical host. I'm up to the step where the VM's are running. Now I need to ssh into the VM's via their DHCP addresses. I can pull the IP addresses from the server but I need a way to set these to host_vars. Here are my groups:</p>
  
  <pre><code>ok: [kvm01] =&gt; {
      "msg": {
          "all": [
              "kvm01",
              "dcos-master-1",
              "dcos-agent-1",
              "dcos-agent-2",
              "dcos_bootstrap"
          ],
          "dcos": [
              "dcos-master-1",
              "dcos-agent-1",
              "dcos-agent-2",
              "dcos_bootstrap"
          ],
          "dcos-agents": [
              "dcos-agent-1",
              "dcos-agent-2"
          ],
          "dcos-bootstraps": [
              "dcos_bootstrap"
          ],
          "dcos-masters": [
              "dcos-master-1"
          ],
          "kvm": [
              "kvm01"
          ],
          "ungrouped": []
      }
  }
  </code></pre>
  
  <p>Here's my command:</p>
  
  <pre><code>- name: Get the IP of the VM (DHCP)
    command: "/getip.sh {{ item }}"
    register: "result"
    with_items: "{{ groups['dcos'] }}"
  
  - name: List the output of the variables
    debug: msg="{{item.stdout}}"
    with_items: "{{result.results}}"
  </code></pre>
  
  <p>When I run the playbook I get results but they are the FULL JSON result of the command rather than the stdout. There's probably a way to pull out the stdout and assign it to a fact but it's a complex hash. Here's the last result:</p>
  
  <pre><code>TASK [vm_install : Get the IP of the VM (DHCP)] ***************************************************************************
  changed: [kvm01] =&gt; (item=dcos-master-1)
  changed: [kvm01] =&gt; (item=dcos-agent-1)
  changed: [kvm01] =&gt; (item=dcos-agent-2)
  changed: [kvm01] =&gt; (item=dcos_bootstrap)
  
  TASK [vm_install : List the output of the variables] **********************************************************************
  ......
      ok: [kvm01] =&gt; (item={'_ansible_parsed': True, 'stderr_lines': [u'] =&gt; {
      "item": {
          "changed": false,
          "cmd": [
              "/getip.sh",
              "dcos_bootstrap"
          ],
          "delta": "0:00:00.056193",
          "end": "2017-09-18 15:45:45.409693",
          "invocation": {
              "module_args": {
                  "_raw_params": "/getip.sh dcos_bootstrap",
                  "_uses_shell": false,
                  "chdir": null,
                  "creates": null,
                  "executable": null,
                  "removes": null,
                  "warn": true
              }
          },
          "item": "dcos_bootstrap",
          "rc": 0,
          "start": "2017-09-18 15:45:45.353500",
          "stderr": " ",
          "stdout": "192.168.1.130",
          "stdout_lines": [
              "192.168.1.130"
          ]
      },
      "msg": "192.168.1.130"
  }
  </code></pre>
  
  <p>How can I put the output of the command into an array so that I can use it later in my playbook?</p>