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
  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 }}" > ~/.ssh/"{{ keyname }}".pem &&
        chmod 600 ~/.ssh/"{{ keyname }}".pem
      with_dict: mykey
      when: item.value.private_key is defined
Apr 8 in Ansible by Aisha
64 views

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 8 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,810 points
111 views
0 votes
1 answer
+13 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 26, 2018 in DevOps & Agile by DragonLord999
• 8,380 points
145 views
0 votes
1 answer
0 votes
1 answer

Error while creating resource group on Azure using Ansible

Hey, @Kiara seems like you're using an ...READ MORE

answered Mar 26 in Ansible by Olly
49 views
0 votes
1 answer

Error when executing ansible playbook on Azure

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

answered Jan 28 in Ansible by Kavya
37 views