大网数据广告活动
服务器运维问答

How does the formatting policy look like since Ansible 2.0?

· 52CE 我爱测

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 Github example The following exa…

问题原文

原帖链接 · 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

Github example

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

  1. Should name (name) be used or a comment (#)?
  2. Should it be file: state=link src=/usr/lib/rabbitmq/bin dest=/usr/lib/rabbitmq/sbin or 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.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-08-04)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。