gpt4 book ai didi

ansible - 从ansible中的yaml文件导入变量

转载 作者:行者123 更新时间:2023-12-05 05:06:55 26 4
gpt4 key购买 nike

我正在尝试从 yaml 文件导入变量并在角色中使用它们,但是我正在尝试以一种方式导入变量,以便我在角色中导入的任何任务文件也可以毫无问题地使用相同的变量。因此,简单来说,我正在尝试为多个角色或任务文件可以使用的变量创建一种 repo 协议(protocol),并且可以保留该值。我从文档中找到的代码是:

  include_vars:
dir: /projects/Variable_files
files_matching:
- default.yml
- debian.yml
name: default_vars

但是我收到了这个错误:

ERROR! 'include_vars' is not a valid attribute for a Play. The error appears to be in '/projects/wordpress.yml': line 2, column 3, but may be elsewhere in the file depending on the exact syntax problem.

最佳答案

缺少破折号 -。正确的语法是

- include_vars:
dir: /projects/Variable_files
files_matching: '^(.*).yml$'
name: default_vars

除此之外,参数files_matching是一个带有正则表达式的字符串。例如 ^(.*).yml$ 匹配所有扩展名为 yml 的文件。参见 include_vars .

可以使用 first_found从列表中选择一个文件。例如,参见 Generic way to list installed packages using Ansible .


尽管参数 files_matching 应该是一个字符串,但列表也可以工作

- include_vars:
dir: /projects/Variable_files
files_matching:
- default.yml
- debian.yml
name: default_vars

关于ansible - 从ansible中的yaml文件导入变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59607343/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com