2017-03-21 3 views
0

I am trying to create a keypair in aws using Ansible but it is throwing me below error: ERROR! with_dict expects a dictAsible - FEHLER! with_dict erwartet eine 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 

Antwort

1

Ich nehme an, Sie verwenden ansible 2.x so versuchen:

with_dict: "{{ mykey }}" 

Wenn das immer noch nicht aktualisieren, funktioniert Ihre Frage mit dem Ausgang:

- name: create a key-pair 
    ... 

- debug: 
    var: result 

- name: write private key to a file 
    ... 
+0

Dank talentfulmrjones, "{{mykey}}" hat gut funktioniert – ricky

+0

Akzeptieren Sie diese Antwort? – talentedmrjones

+0

Gutes Auge! Korrigiert, danke. – talentedmrjones