安装与管理 Ansible 角色和集合
ansible-galaxy 从 Galaxy 或私有源安装角色(role)和集合(collection),也用于初始化、构建和发布。集合是当前推荐的分发单位。
ansible-galaxy collection install community.general
ansible-galaxy collection install -r requirements.yml
ansible-galaxy collection list
ansible-galaxy role install geerlingguy.nginx
ansible-galaxy role init myrole
ansible-galaxy collection init myns.mycol
ansible-galaxy collection build
ansible-galaxy collection publish myns-mycol-1.0.0.tar.gz
ansible-galaxy install -r requirements.yml -p ./roles
requirements.yml:
collections:
- name: community.general
version: ">=8.0.0,<9.0.0"
- name: ansible.posix
version: 1.5.4
roles:
- name: geerlingguy.nginx
version: 3.1.4
ansible_collections/<namespace>/<name>;手工放置容易找不到。install 默认联网。requirements.yml 的 collections/roles 段落格式不同;YAML 缩进错误会静默漏装。--list 或 dry-run 确认。合上页面,先回答,再展开对照。
requirements.yml 里锁定版本?ansible-galaxy collection install 会有什么问题?应该怎么准备?ansible_collections/<namespace>/<name>,手工放置时目录结构不对就会找不到。install 默认联网,离线环境会失败;要提前下载 tarball 或使用私有 Galaxy 源。
小程序版
微信扫码,随时查命令