title: Asible - ERROR! with_dict expects a dict
body: <blockquote>
    <p>I am trying to create a keypair in aws using Ansible but it is
    throwing me below error:
    <strong>ERROR! with_dict expects a dict</strong></p>
    
    <p>Below is my keypair.yml</p>
  </blockquote>
  
  <pre><code>---
  - hosts: localhost
    connection: local
    gather_facts: no
    vars:
      region: ap-southeast-1
      keyname: aws_ansible
    tasks:
      - name: create a key-pair
        local_action:
          module: ec2_key
          region: "{{region}}"
          name: "{{keyname}}"
          state: present
        register: mykey
  
      - name: write private key to a file
        local_action: shell echo -e "{{ item.value.private_key }}" &gt; ~/.ssh/"{{ keyname }}".pem &amp;&amp;
          chmod 600 ~/.ssh/"{{ keyname }}".pem
        with_dict: mykey
        when: item.value.private_key is defined
  </code></pre>