title: Ansible how to access list of dictionaries when using with_together
body: <p>I am trying to create an ansible playbook which will allow me to create an AWS Lambda in a number of regions, and for each Lambda also register an SNS with the Lambda as a trigger. (If I am misunderstanding the process please feel free to point out my mistake, I am not 100% what I am doing is correct)</p>
  
  <p>I have the following code in Ansible:</p>
  
  <pre><code>      lambda:
          name: "{{ item[0] }}"
          state: present
          s3_bucket: "my-devops-lambdas-{{ item[1] }}"
          s3_key: "{{ item[0] }}.zip"
          runtime: python3.6
          role: arn:aws:iam::****:role/devops-lambdas
          handler: lambda.lambda_handler
          region: "{{ item[1] }}"
        register: lambda_config
        with_items:
          - "{{ projects_to_build.stdout | from_json }}"
  
      - name: Register SNS
        sns_topic:
          name: "{{ item.0[2] }}"
          region: "{{ item.0[0] }}"
          subscriptions:
            - protocol: LAMBDA
            - endpoint: "{{ item.1.configuration.function_arn }}"
        with_together:
          - "{{ projects_to_build.stdout | from_json }}"
          - "{{ lambda_config.results }}"
  </code></pre>
  
  <p>My <code>projects_to_build</code> looks like this:</p>
  
  <pre><code>    "failed": false, 
      "projects_to_build.stdout": [
          [
              "cloudwatch-to-slack", 
              "eu-west-2", 
              "arn:aws:sns:eu-west-2:****:slack_devops"
          ], 
          [
              "cloudwatch-to-slack", 
              "eu-west-1", 
              "arn:aws:sns:eu-west-1:****:slack_devops"
          ]
      ]
  }
  </code></pre>
  
  <p>I think I should be using <code>with_subelements</code> in order to access the items within my <code>lambda_config</code> results, but I don't see how I can use that at the same time as <code>with_together</code>.</p>
  
  <p>I would post the <code>lambda_config</code> here, but it is huge, the format of the config is similar to <a href="https://docs.ansible.com/ansible/latest/modules/lambda_module.html" rel="nofollow noreferrer">this</a> except that because I have multiple lambdas being created the results are a dictionary with <code>results</code> being a list of the results for each lambda created.</p>
  
  <p>I am using Ansible 2.6, so I can use the new loops method instead of with_together, but so far I have been unable to find any way that will work.</p>
  
  <p>I get this error when I try to run as is:</p>
  
  <pre><code>TASK [Register SNS] ************************************************************
  fatal: [localhost]: FAILED! =&gt; {"failed": true, "msg": "The task includes an option with an undefined variable. The error was: 'ansible.utils.unsafe_proxy.AnsibleUnsafeText object' has no attribute 'configuration'\n\nThe error appears to have been in '/var/lib/jenkins/workspace/Global/devops-lambdas/aws/shared/deploy-devops-lambdas.yml': line 46, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n    - name: Register SNS\n      ^ here\n"}
      to retry, use: --limit @/var/lib/jenkins/workspace/Global/devops-lambdas/aws/shared/deploy-devops-lambdas.retry
  </code></pre>
  
  <p>I have tried a number of other solutions, one I thought might work was to use:</p>
  
  <pre><code>      with_together:
          - "{{ projects_to_build.stdout | from_json }}"
          - "{{ lambda_config.results | list }}"
  </code></pre>
  
  <p>That results in the same error. How do I iterate through the list of lambda results contained within <code>lambda_config.results</code>?</p>
  
  <p>====EDIT DEBUG====</p>
  
  <p>I already had a debug step, and it does appear as I was expecting @larsks it hasn't helped me so far, maybe it can help you?</p>
  
  <pre><code>TASK [debug] *******************************************************************
  ok: [localhost] =&gt; {
      "failed": false, 
      "lambda_config": {
          "changed": true, 
          "msg": "All items completed", 
          "results": [
              {
                  "_ansible_ignore_errors": null, 
                  "_ansible_item_result": true, 
                  "_ansible_no_log": false, 
                  "_ansible_parsed": true, 
                  "changed": true, 
                  "code": {
                      "location": "https://awslambda-eu-west-2-tasks.s3.eu-west-2.amazonaws.com/snapshots/****/cloudwatch-to-slack-cf94f4d9-fc73-495b-aff5-b6c619d38b28?versionId=kzf3OeHyAo1KAYF.WidtJch0730rckRa&amp;X-Amz-Security-Token=IQoJb3JpZ2luX2VjEAYaCWV1LXdlc3QtMiJHMEUCIQCjBXJcZKqxWX%2FMuj0zrAWO2UMMVyY22sCB%2Fo4YM02yqgIgBXVv0h2efZNqtjOJuyJlUAU0ou6StJLTXiBQzn%2B5BY4q0gIILhABGgw0NzIwMzg4NjQxODgiDDWKUw4k946LccANVCqvAgv5WC7AbvV9IhdAd3kXXGIxTqnRYJsneoNXYgf3BC3tRAYxrq2D0u0iL7HAqGqL97L6IRneu4H5pDqHalSfgBvriSrI8hDpDLsNJ08d9pMFigOWM9HWpi0rCwkRRG7FSjNgT4oqqZwUEcQl7H36a53qAdFGUp60S6Y4nZxuOkg3jgiyx6fkyXy8MAWxk8A6AogKQc0uubhcIbJNMGLrF3uyoROONdXNVtbJzkIQOZdoXxDW%2BMOr%2BBuyOz8%2F6RZqyiS3FkKCRuhl5GFueSDIW1ZUjzw68aRi1%2BFoCkIjxvf5cvfxwkOYW0UculsbAzv82F1CA3foeKUpR%2FWzUl5HRKzzB7MuZNntwac7rPOSbDNgAvbAdRibbUUbETDnBm7BmMalx9V%2BMXeK%2BHNHuk2eQDDsnbDuBTrNAl6I1SKoiX0iU5lvWmm8yXpE8NEA98g%2F1xzbmGlMPAFDg3sX19zts5xK%2BcYuZ9NG1kfReW7lo7kDVCTvGIhZmF9%2B%2FK2mmo%2FIoTYY6v7WygsrgyG2QGaE%2B5BdljJ1Kpb05We1v877JJNxrwX%2BhyUH2iD8wJS4k2bMum%2FytT02YnX014kSW21V6UVqMYftmcZ%2BYAE%2BQWdxqYgJtry9ZJFEdwwYAkJ2wgvqoLtBK3aaVQRDYw0TXtOnATi5EVn%2FQobtNO%2BXVmqflcGdJrtlVapFqKqX17eJw6KvnRo9%2BeMQ5OAKMt6xVA1p%2F3uxxIhQuyB9b8maRMg3TWfiUs%2FpYhjHQI%2FDaz00dAllvQBvjR%2FFjAeP76%2BVQzpiBW1tLQTBqzJZ1aQqfOB7vV6KkqSok%2BndT1hFwRbFgf76AboKGfwWuVHh7g0aWtnzQ%2FFF%2Fmizcg%3D%3D&amp;X-Amz-Algorithm=AWS4-HMAC-SHA256&amp;X-Amz-Date=20191113T150904Z&amp;X-Amz-SignedHeaders=host&amp;X-Amz-Expires=600&amp;X-Amz-Credential=ASIAW3Z5VOU6FMHUHSL2%2F20191113%2Feu-west-2%2Fs3%2Faws4_request&amp;X-Amz-Signature=eb46bba09f8496841d67f2b24a042b0a3467fae7adcf1149bb8ca1e269f1604e", 
                      "repository_type": "S3"
                  }, 
                  "configuration": {
                      "code_sha256": "LmvHp5ZwvJXHK4pvVFOQqjtW13izWo2Kv4sJ6l1j7XY=", 
                      "code_size": 12098675, 
                      "description": "", 
                      "function_arn": "arn:aws:lambda:eu-west-2:****:function:cloudwatch-to-slack:20", 
                      "function_name": "cloudwatch-to-slack", 
                      "handler": "lambda.lambda_handler", 
                      "last_modified": "2019-11-13T15:09:04.488+0000", 
                      "memory_size": 128, 
                      "revision_id": "cd9af309-a209-4630-897a-9ee5e7c164cb", 
                      "role": "arn:aws:iam::****:role/devops-lambdas", 
                      "runtime": "python3.6", 
                      "timeout": 3, 
                      "tracing_config": {
                          "mode": "PassThrough"
                      }, 
                      "version": "20"
                  }, 
                  "failed": false, 
                  "invocation": {
                      "module_args": {
                          "aws_access_key": null, 
                          "aws_secret_key": null, 
                          "dead_letter_arn": null, 
                          "description": "", 
                          "ec2_url": null, 
                          "environment_variables": null, 
                          "handler": "lambda.lambda_handler", 
                          "memory_size": 128, 
                          "name": "cloudwatch-to-slack", 
                          "profile": null, 
                          "region": "eu-west-2", 
                          "role": "arn:aws:iam::****:role/devops-lambdas", 
                          "runtime": "python3.6", 
                          "s3_bucket": "my-devops-lambdas-eu-west-2", 
                          "s3_key": "cloudwatch-to-slack.zip", 
                          "s3_object_version": null, 
                          "security_token": null, 
                          "state": "present", 
                          "tags": null, 
                          "timeout": 3, 
                          "validate_certs": true, 
                          "vpc_security_group_ids": null, 
                          "vpc_subnet_ids": null, 
                          "zip_file": null
                      }
                  }, 
                  "item": [
                      "cloudwatch-to-slack", 
                      "eu-west-2", 
                      "arn:aws:sns:eu-west-2:****:slack_devops"
                  ], 
                  "response_metadata": {
                      "http_headers": {
                          "connection": "keep-alive", 
                          "content-length": "2451", 
                          "content-type": "application/json", 
                          "date": "Wed, 13 Nov 2019 15:09:04 GMT", 
                          "x-amzn-requestid": "deb5eab6-39d8-451c-851a-096da70056ee"
                      }, 
                      "http_status_code": 200, 
                      "request_id": "deb5eab6-39d8-451c-851a-096da70056ee", 
                      "retry_attempts": 0
                  }
              }, 
              {
                  "_ansible_ignore_errors": null, 
                  "_ansible_item_result": true, 
                  "_ansible_no_log": false, 
                  "_ansible_parsed": true, 
                  "changed": true, 
                  "code": {
                      "location": "https://awslambda-eu-west-1-tasks.s3.eu-west-1.amazonaws.com/snapshots/****/cloudwatch-to-slack-dad6d47a-b4d6-4d03-8300-e9a47e652415?versionId=510url5wG1BMpTNk047YFeKYDpPwH9HH&amp;X-Amz-Security-Token=IQoJb3JpZ2luX2VjEAYaCWV1LXdlc3QtMSJGMEQCIBXrZqSZ4rvZKX27JqGrh2I1lUXqcYbFEu65TsYYaD7yAiBACK9qTPJFttLMbhNglvrKI%2F80hGO2hRn2wlRHIcY2hSrRAgguEAEaDDk1NDM2OTA4MjUxMSIMEQgZtz75PVoFjg%2FSKq4CYnr%2BXPNGag8Y5s3mncAQJbftOPYRffNPV1tsJcN%2BEYANTgKaiNBv%2FkOLpKLNaTuTtPZVa%2F6PO20zsD6GBK%2BeQL0craOJhNmawU50vpRlGIWyQKHhPyGbidr3%2FjE6eN%2B9TfHmrp2HyxfOy8L8wMfa%2BuuRfSsVlE3qdu57zhXCOClb2HFcbDrOLCS%2BFyDuFAFxDmeZ8wLlOv%2BiSIJvwX0LcXNHXmRhpKbqQ%2F8tsOLkwnfW80ri5PVvO9f9%2FOq5spEC8PWNbaSp5TEsnzPodM14PD1E4TIDn1UogDueIUvZ2nJRHCGw4P7glzI78e1NcMPT5eJAr2zT50V3nkT%2FlKgX5M7tnFhnW9IXdHxTIOIwjtVun4jUCSFh5897wPTb39tGLl163sCuM8FjxMKC5Lowy52w7gU6zwIOVYWYv%2B02dlMT5TV0mOCHxXnGx4DEORRcYJyVAHNVLK0%2BLaFcNWcS6YLKWNnSwBVc0uL2agamVB%2FU1bOBNBePTtT71icqxaMBfgOeztW%2BdH9Z%2BtH9e49QBCR4RqtuWd%2BdqW2oSwU78qiHYDbD0C6I9ncp546Q96BkEy%2FGTdSxLHr6dK%2BzGC5B39z6Vm8U4vEr22%2B8q44PuRx6dvIAE36VoiE9yEVJ4lAePb924VHEgnSxFEWUxQwNeoRcydU2%2BD1X34%2FForAo8upzZDOJl47eSv5SsQltGi0FsTkvhCld9aYT3EKWywXp8AJUalWSONtFXToh5xCc%2F3chuho5MkssdShdXi3wpX9epgRP0rYFSOh0VoeTZ6PauQ2B8dzK58adkwvTXuefYzNk6Yei%2Bei%2B8Wn0%2FIbU8k5L0YAiT%2FMrObPjtbcVmFRY%2FWYDlc8G7g%3D%3D&amp;X-Amz-Algorithm=AWS4-HMAC-SHA256&amp;X-Amz-Date=20191113T150906Z&amp;X-Amz-SignedHeaders=host&amp;X-Amz-Expires=600&amp;X-Amz-Credential=ASIA54NGUQSH3ABZBRID%2F20191113%2Feu-west-1%2Fs3%2Faws4_request&amp;X-Amz-Signature=8cb09d879f729f19d01c11fc2deb1d49a6e409f2284878d879e6f197ad73f67d", 
                      "repository_type": "S3"
                  }, 
                  "configuration": {
                      "code_sha256": "cW3LqsTkdXwBacHpRvgfruZ7svIhy7gvB80keZqVpjw=", 
                      "code_size": 12100273, 
                      "description": "", 
                      "function_arn": "arn:aws:lambda:eu-west-1:****:function:cloudwatch-to-slack:21", 
                      "function_name": "cloudwatch-to-slack", 
                      "handler": "lambda.lambda_handler", 
                      "last_modified": "2019-11-13T15:09:05.780+0000", 
                      "memory_size": 128, 
                      "revision_id": "e48a6926-fd7c-44f8-9e1f-3f24e0fc82fb", 
                      "role": "arn:aws:iam::****:role/devops-lambdas", 
                      "runtime": "python3.6", 
                      "timeout": 3, 
                      "tracing_config": {
                          "mode": "PassThrough"
                      }, 
                      "version": "21"
                  }, 
                  "failed": false, 
                  "invocation": {
                      "module_args": {
                          "aws_access_key": null, 
                          "aws_secret_key": null, 
                          "dead_letter_arn": null, 
                          "description": "", 
                          "ec2_url": null, 
                          "environment_variables": null, 
                          "handler": "lambda.lambda_handler", 
                          "memory_size": 128, 
                          "name": "cloudwatch-to-slack", 
                          "profile": null, 
                          "region": "eu-west-1", 
                          "role": "arn:aws:iam::****:role/devops-lambdas", 
                          "runtime": "python3.6", 
                          "s3_bucket": "my-devops-lambdas-eu-west-1", 
                          "s3_key": "cloudwatch-to-slack.zip", 
                          "s3_object_version": null, 
                          "security_token": null, 
                          "state": "present", 
                          "tags": null, 
                          "timeout": 3, 
                          "validate_certs": true, 
                          "vpc_security_group_ids": null, 
                          "vpc_subnet_ids": null, 
                          "zip_file": null
                      }
                  }, 
                  "item": [
                      "cloudwatch-to-slack", 
                      "eu-west-1", 
                      "arn:aws:sns:eu-west-1:****:slack_devops"
                  ], 
                  "response_metadata": {
                      "http_headers": {
                          "connection": "keep-alive", 
                          "content-length": "2453", 
                          "content-type": "application/json", 
                          "date": "Wed, 13 Nov 2019 15:09:06 GMT", 
                          "x-amzn-requestid": "78704b46-7dce-49c1-961e-cb8882088566"
                      }, 
                      "http_status_code": 200, 
                      "request_id": "78704b46-7dce-49c1-961e-cb8882088566", 
                      "retry_attempts": 0
                  }
              }
          ]
      }
  }
  </code></pre>