ERROR with dict expects a dict - When creating a new keypair using Ansible

0 votes

I am trying to create a keypair in aws using Ansible but it is throwing me below error: 

ERROR! with_dict expects a dict

Below is my keypair.yml

- hosts: localhost
  connection: local
  gather_facts: no
    region: ap-southeast-1
    keyname: aws_ansible
    - name: create a key-pair
        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 }}" > ~/.ssh/"{{ keyname }}".pem &&
        chmod 600 ~/.ssh/"{{ keyname }}".pem
      with_dict: mykey
      when: item.value.private_key is defined
Apr 9, 2019 in Ansible by Aisha

1 answer to this question.

0 votes

Depends on the version you're using. I'm assuming you're using Ansible 2.x. 

Try this:

with_dict: "{{ mykey }}"
answered Apr 9, 2019 by Anshul

Related Questions In Ansible

0 votes
1 answer

How can I create a new user using ansible ploybook?

You're switching from the root user. Root ...READ MORE

answered Mar 29, 2018 in Ansible by DareDev
• 6,890 points
0 votes
1 answer
+15 votes
2 answers

Git management technique when there are multiple customers and need multiple customization?

Consider this - In 'extended' Git-Flow, (Git-Multi-Flow, ...READ MORE

answered Mar 27, 2018 in DevOps & Agile by DragonLord999
• 8,450 points
+2 votes
1 answer
0 votes
2 answers

Error while creating resource group on Azure using Ansible

Please check you indentation, remove all spaces ...READ MORE

answered Mar 17, 2020 in Ansible by Shrikant Yerge
0 votes
1 answer

Error when executing ansible playbook on Azure

Hey @Ganga, As the error message says, ...READ MORE

answered Jan 29, 2019 in Ansible by Kavya