gpt4 book ai didi

Ansible 角色。默认值

转载 作者:行者123 更新时间:2023-12-02 17:12:30 27 4
gpt4 key购买 nike

我在文档中找不到答案,也找不到示例:是否可以在 role/defaults/ 中命名除 main.yml 之外的文件?我的意思是,main.yml 是具有默认值的文件的唯一有效名称吗?

最佳答案

根据本文档的声音;

http://docs.ansible.com/ansible/playbooks_roles.html#roles

Roles are just automation around ‘include’ directives as describedabove, and really don’t contain much additional magic beyond someimprovements to search path handling for referenced files. However,that can be a big thing!

This designates the following behaviors, for each role ‘x’:

If roles/x/tasks/main.yml exists, tasks listed therein will be addedto the play

If roles/x/handlers/main.yml exists, handlers listedtherein will be added to the play

If roles/x/vars/main.yml exists,variables listed therein will be added to the play

Ifroles/x/defaults/main.yml exists, variables listed therein will beadded to the play

If roles/x/meta/main.yml exists, any roledependencies listed therein will be added to the list of roles (1.3and later) Any copy, script, template or include tasks (in the role)can reference files in roles/x/{files,templates,tasks}/ (dir dependson task) without having to path them relatively or absolutely

问:我的意思是,main.yml 是具有默认值的文件的唯一有效名称吗?
答:听起来只有当您希望 ansible 自动加载该角色的某些 var_files 并自动包含任务文件时才如此。

问:是否可以命名文件
答:是的,这只是意味着在剧本中您必须使用include指令并明确地将其指向唯一的任务文件名。

示例:

- name: Do role
hosts: localhost
tasks:
- include: roles/operations/tasks/installProgram.yml

关于Ansible 角色。默认值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39648959/

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