在Ansible中,角色(roles)和集合(collections)的命名应遵循以下规则:
- 角色和集合的名称只能由小写字母、数字、破折号或下划线组成。
- 角色名必须以字母开头,集合名可以以数字开头。
- 角色和集合的名称中不得使用特殊字符或空格。
- 破折号(-)和下划线(_)都可以用作单词分隔符。
- 使用破折号(-)作为分隔符更常见,因为在Ansible中,通常使用破折号来表示单词之间的空格。
示例代码:
Example role with dash-separated name:
roles/example-role/tasks/main.yml
- name: Example task
debug:
msg: "This is an example task in a role named 'example-role'"
Example collection with underscore-separated name:
collections/example_collection/plugins/module/example.py
def example_function():
return "Hello, world! This is an example function inside a collection named 'example_collection'"