Asible - 错误! with_dict 需要一个字典
Asible - ERROR! with_dict expects a dict
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
我假设您使用的是 Ansible 2.x 所以请尝试:
with_dict: "{{ mykey }}"
如果仍然无效,请使用以下输出更新您的问题:
- name: create a key-pair
...
- debug:
var: result
- name: write private key to a file
...
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
我假设您使用的是 Ansible 2.x 所以请尝试:
with_dict: "{{ mykey }}"
如果仍然无效,请使用以下输出更新您的问题:
- name: create a key-pair
...
- debug:
var: result
- name: write private key to a file
...