Ansible 模块参数语法

发布于 2025-01-15 01:19:20 字数 514 浏览 1 评论 0原文

为什么要执行的命令任务下的playbook.yml上,有的模块有引号,有的模块没有?

例如,如果您检查下面的语法,模块 line 嵌入在引号中,但 script 则没有。

- name: 'Execute a script on all web server nodes and start httpd service'
  hosts: web_nodes

  tasks:

    - name: 'Update entry into /etc/resolv.conf'
      lineinfile:
        path: /etc/resolv.conf
        line: 'nameserver 10.1.250.10' 

    - name: 'Execute a script'
      script: /tmp/install_script.sh

Why is it that on the playbook.yml under the command task to be executed, some modules have a quotation mark while some does not?

For example, if you check the syntax below, the module line is with embedded in a quotation mark but script is not.

- name: 'Execute a script on all web server nodes and start httpd service'
  hosts: web_nodes

  tasks:

    - name: 'Update entry into /etc/resolv.conf'
      lineinfile:
        path: /etc/resolv.conf
        line: 'nameserver 10.1.250.10' 

    - name: 'Execute a script'
      script: /tmp/install_script.sh

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

卷耳 2025-01-22 01:19:20

两个模块均采用 line 的参数cmd 一个字符串。

为什么...有的模块有引号,有的没有?

您的问题是关于 YAML 语法

这就是 Ansible playbook(我们的配置管理语言)的表达方式。

何时引用< /a> 和 YAML 陷阱

虽然您可以将任何内容放入不带引号的标量中,但也有一些例外。

风格指南也可能是何时以及如何引用不同方式的原因。

Both modules take as parameter for line or cmd a string.

Why is it that ... some modules have a quotation mark while some does not?

Your question is about the YAML Syntax

which is how Ansible playbooks (our configuration management language) are expressed.

when to quote and YAML Gotchas

While you can put just about anything into an unquoted scalar, there are some exceptions.

Also a style guide can be a reason of different ways of when and how to quote.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文