Ansible:“这个模块需要键=值参数";当提供 key=value 参数时 [英] Ansible: "this module requires key=value arguments" when key=value args supplied
问题描述
我从 Ansible 1.9.4 收到此错误:
I'm getting this error from Ansible 1.9.4:
TASK: [rabbitmq | add rabbitmq vhost] *****************************************
failed: [prod-sensu01] => (item={'name': u'/sensu'})
=> {"failed": true, "item": {"name": "/sensu"}}
msg: this module requires key=value arguments
(['name:', '/sensu', 'node:', 'rabbit',
'tracing:', 'no', 'state:', 'present'])
但是从错误信息中可以看出,该项目实际上是一个键=值参数(哈希).
But as you can see from the error message, the item is actually a key=value argument (hash).
这里是变量:
# playbooks/roles/rabbitmq/vars/main.yml
# Set the rabbitmq vhost
rabbitmq_vhost_definitions:
- name: "{{ sensu_server_rabbitmq_vhost }}"
以及角色的任务:
# playbooks/roles/rabbitmq/tasks/vhost.yml
- name: add rabbitmq vhost
rabbitmq_vhost: >
name: "{{ item.name }}"
node: "{{ item.node | default('rabbit') }}"
tracing: "{{ item.tracing | default('no') }}"
state: present
with_items: rabbitmq_vhost_definitions
这里发生了什么?
推荐答案
作为字符串传递的 Ansible 模块参数的键/值对应该用 =
分隔,而不是 :代码>.正确的任务应该是这样的:
Key/value pairs of arguments for Ansible module passed as string should be separated by =
, not by :
. Correct task should look like this:
# playbooks/roles/rabbitmq/tasks/vhost.yml
- name: add rabbitmq vhost
rabbitmq_vhost: >
name="{{ item.name }}"
node="{{ item.node | default('rabbit') }}"
tracing="{{ item.tracing | default('no') }}"
state=present
with_items: rabbitmq_vhost_definitions
为什么它们作为字符串传递?因为您在模块名称后使用折叠块标量 >
,所以在这一行:
Why they're passed as string? Because you're using folded block scalar >
after name of the module, in this line:
rabbitmq_vhost: >
如果此模块支持两种传递参数的方式,您也可以尝试删除 >
标量(并保留冒号).
You could also try to remove >
scalar (and leave colons) if this module supports both ways of passing arguments.
这篇关于Ansible:“这个模块需要键=值参数";当提供 key=value 参数时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!