问题原文
原帖链接 · 030 · CC BY-SA 3.0
I have seen multiple Ansible examples on github and in the ansible docs, e.g.:
---
# this might be in a file like handlers/handlers.yml
- name: restart apache
service: name=apache state=restarted
The following example contains both a comment as a name.
# Make sure Jenkins starts, then configure Jenkins.
- name: Ensure Jenkins is started and runs on startup.
service: name=jenkins state=started enabled=yes
Discussion
A name would be sufficient right or should a comment be used?
Should it be:
- name: Symlink RabbitMQ bin to sbin
file: state=link src=/usr/lib/rabbitmq/bin dest=/usr/lib/rabbitmq/sbin
or:
#Symlink RabbitMQ bin to sbin
file:
state: link
src: /usr/lib/rabbitmq/binhttp://docs.ansible.com/ansible/YAMLSyntax.html
dest: /usr/lib/rabbitmq/sbin
When YAML Lint is consulted as recommended by the Ansible YAML syntax doc both snippets seem to be valid YAML. Although both snippets seem to be valid YAML the visual structure is different.
Questions
- Should name (
name) be used or a comment (#)? - Should it be
file: state=link src=/usr/lib/rabbitmq/bin dest=/usr/lib/rabbitmq/sbinor should the elemented by split up, e.g.state:
社区高分解答
原帖链接 · Henrik Pingel · CC BY-SA 3.0
That is up to your own preference.
Comments like # Make sure Jenkins starts, then configure Jenkins. don't make much sense as they don't add more information.
Inline syntax is supported by YAML to be compatible with JSON. Outline syntax however should be preferred because, the code is better readable and code changes can be reviewed better with diff.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
