title: Retrieve key's value from registered variable in ansible
body: <p>I am writing various playbooks for the provisioning of users, groups, policies etc in AWS.</p>
  
  <p>At the moment, I am trying to write a task that will remove any access keys from a given AWS IAM account. To properly do so using the iam module in ansible, you must specify the AWS access key that you wish to disable.</p>
  
  <p>This script also creates a user before hand (the removing of access keys is to assure that if the user was already created, they don't have any left over access keys from before).</p>
  
  <p>The output of the user creation is registered into a variable like so</p>
  
  <pre><code>- name: Create new user and add to IAM group for console
    vars:
      use_key: "{{ enable_access_keys }}"
    iam:
      iam_type: user
      name: "{{ item }}"
      state: present
      aws_access_key: "{{ account_vars.aws_access_key }}"
      aws_secret_key: "{{ account_vars.aws_secret_key }}"
      password: "{{ iam_password }}"
      update_password: on_create
    with_items:
      - "{{ iam_user_name_list }}"
    when: not use_key
    register: console_user
  </code></pre>
  
  <p>The output of the console_user var is:</p>
  
  <pre><code>ok: [127.0.0.1] =&gt; {
      "changed": false,
      "msg": {
          "changed": false,
          "msg": "All items completed",
          "results": [
              {
                  "_ansible_item_result": true,
                  "_ansible_no_log": false,
                  "_ansible_parsed": true,
                  "changed": false,
                  "groups": null,
                  "invocation": {
                      "module_args": {
                          "access_key_ids": null,
                          "access_key_state": null,
                          "aws_access_key": "removed",
                          "aws_secret_key": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
                          "ec2_url": null,
                          "groups": null,
                          "iam_type": "user",
                          "key_count": 1,
                          "name": "other-guy",
                          "new_name": null,
                          "new_path": null,
                          "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
                          "path": "/",
                          "profile": null,
                          "region": null,
                          "security_token": null,
                          "state": "present",
                          "trust_policy": null,
                          "trust_policy_filepath": null,
                          "update_password": "on_create",
                          "validate_certs": true
                      }
                  },
                  "item": "other-guy",
                  "keys": {
                      "Access key is here": "Active"
                  },
                  "user_name": "other-guy"
              }
          ]
      }
  }
  </code></pre>
  
  <p>My question is, how can I get the access key that is provided under the "keys" dictionary? Since the what I'm looking for is the key, not the value, I'm not sure how I would go about obtaining that access key so I can use it in the next task to say that I'd like to remove it.</p>
  
  <p>Thanks in advance for any help.</p>