Ansible教程

Ansible Galaxy

Ansible Galaxy

Ansible Galaxy 是一个 Galaxy 网站,用户可以在其中共享角色并使用命令行工具安装、创建、和管理角色。
Ansible Galaxy 使 Ansible 最令人兴奋的功能之一更加清晰,例如应用程序安装或服务器配置的可重用角色。许多人在 Ansible Galaxy 中共享角色。
Ansible 角色由许多剧本组成,这是一种将多个任务分组到一个容器中的方法,以非常有效的方式通过干净的目录结构进行自动化。

Ansible Galaxy 命令

以下是一些有用的 Ansible Galaxy 命令,例如:
显示已安装角色的列表,以及版本号。
ansible-galaxy list
删除已安装的角色。
ansible-galaxy remove [role]
创建适合提交到 Ansible Galaxy 的角色模板。
ansible-galaxy init

使用 Ansible Galaxy 创建角色

Ansible Galaxy 本质上是 Ansible 角色的大型公共存储库。角色附带详细说明角色使用和变量的自述文件。 Ansible Galaxy 包含大量不断发展和增加的角色。
Galaxy 可以使用 Git 添加其他角色源,如 GitHub。您可以使用 ansible-galaxy init 初始化新的星系角色,或者通过执行 ansible-galaxy install <角色名称> 直接从 Ansible 星系角色存储安装角色
要使用 Ansible Galaxy 创建 Ansible 角色,您需要使用 ansible-galaxy 命令及其模板。必须先下载角色,然后才能在剧本中使用它们。它们被放置在默认目录即/etc/ansible/roles 中。

创建集合

Ansible Galaxy 一直是一个工具用于使用 Ansible 的新迭代构建和管理角色,您一定会看到更改或添加。在 Ansible 2.8 版中,您可以获得集合的独特功能。
集合是 Ansible 内容的分发格式。它们可用于打包和分发角色、模块、剧本和插件。
集合遵循以下简单结构:
collection/ 
&#x251c;── docs/ 
&#x251c;── galaxy.yml 
&#x251c;── plugins/ 
&#x2502; ├── modules/ 
&#x2502; │ └── module1.py 
&#x2502; ├── inventory/ 
&#x2502; └── .../ 
&#x251c;── README.md 
&#x251c;── roles/ 
&#x2502; ├── role1/ 
&#x2502; ├── role2/ 
│ └── .../ 
&#x251c;── playbooks/ 
&#x2502; ├── files/ 
&#x2502; ├── vars/ 
&#x2502; ├── templates/ 
&#x2502; └── tasks/ 
&#x2514;── tests/
ansible-galaxy-collection 命令实现了以下命令。一些命令与 ansible-galaxy 使用的相同,例如:
init: 它基于 Ansible 中包含的默认模板或您自己的模板创建一个基本集合 Skeleton。 构建: 它创建了一个可以上传到星系或您自己的存储库的集合工件。 发布: 它向星系发布了一个构建的连接工件。 安装: 安装一个或多个连接。
昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4