【发布时间】:2021-02-17 18:20:59
【问题描述】:
Ansible 举个例子:
https://docs.ansible.com/ansible/latest/user_guide/playbooks_tags.html#adding-tags-to-blocks
# myrole/tasks/main.yml
tasks:
- block:
tags: ntp
并说“使用块并在该级别定义标签”,然后在此页面上:
https://docs.ansible.com/ansible/latest/user_guide/playbooks_blocks.html
他们使用:
tasks:
- name: Install, configure, and start Apache
block:
- name: Install httpd and memcached
ansible.builtin.yum:
name:
- httpd
- memcached
state: present
如果我尝试“使用块并在该级别定义标签”,例如与:
tasks:
- name: Install, configure, and start Apache
block:
tag: broken
- name: Install httpd and memcached
或者(绝望中)
tasks:
- name: Install, configure, and start Apache
block:
- tag: broken
- name: Install httpd and memcached
我明白了:
Syntax Error while loading YAML.
did not find expected key
问题是什么?如何为第二个示例添加标签?
【问题讨论】:
-
修复最后两个示例和错误消息。这是
tags不是tag。结果是误导性错误did not find expected key。这里真正的问题是mapping values are not allowed in this context。 -
我不确定我是否理解。我使用的是单个标签而不是多个标签。
-
语法是tags,即使是单个标签。