community.general.ansible_galaxy_install 模块 – 使用 ansible-galaxy 安装 Ansible 角色或集合

注意

此模块是 community.general 集合 (版本 10.1.0) 的一部分。

如果您正在使用 ansible 软件包,您可能已经安装了此集合。它不包含在 ansible-core 中。要检查它是否已安装,请运行 ansible-galaxy collection list

要安装它,请使用: ansible-galaxy collection install community.general。您需要其他需求才能使用此模块,有关详细信息,请参阅 需求

要在 playbook 中使用它,请指定: community.general.ansible_galaxy_install

community.general 3.5.0 中的新增功能

概要

  • 此模块允许使用 ansible-galaxy 安装 Ansible 集合或角色。

需求

执行此模块的主机需要以下需求。

  • ansible-core 2.11 或更高版本

参数

参数

注释

dest

路径

根据 type 的值,包含您的集合或角色的目录的路径。

请注意,当 requirements_file 包含角色和集合,并且 dest 已指定时,ansible-galaxy 将不会安装 type=both 的集合。

force

布尔值

强制覆盖现有的角色和/或集合。

它可用于升级,但模块输出将始终报告 changed=true

降级时,必须使用 force=true

选项

  • false ← (默认)

  • true

name

字符串

正在安装的集合或角色的名称。

可以使用 ansible-galaxy 的常用格式指定版本。例如,集合 community.docker:1.6.1 或角色 ansistrano.deploy,3.8.0

namerequirements_file 是互斥的。

no_deps

布尔值

community.general 4.5.0 中新增

避免安装依赖项。

选项

  • false ← (默认)

  • true

requirements_file

路径

包含要安装的需求列表的文件的路径。

它适用于 type 等于 collectionrole

namerequirements_file 是互斥的。

state

字符串

community.general 9.1.0 中新增

如果 state=present,则将安装集合或角色。请注意,使用此选项不会更新集合和角色。

当前,除非 type=collection,否则将忽略 state=latest,它将确保集合已安装并更新到最新版本。

请注意,无论 type 如何,都可以使用 force=true 执行升级。

选项

  • "present" ← (默认)

  • "latest"

type

字符串 / 必需

ansible-galaxy执行的安装类型。

如果type=both,则必须传递requirements_file,它可以包含角色和集合。

但是请注意,反过来并非如此:如果使用requirements_file,则type可以是三个选项中的任何一个。

选项

  • “collection”(集合)

  • “role”(角色)

  • “both”(两者)

属性

属性

支持

描述

check_mode

支持:不支持

可以在check_mode下运行,并在不修改目标的情况下返回更改状态预测。

diff_mode

支持:不支持

在差异模式下,将返回有关已更改内容(或可能需要在check_mode中更改的内容)的详细信息。

备注

注意

  • community.general 8.0.0 中移除了对**Ansible 2.9/2.10** 的支持。

  • 该模块将尝试使用C.UTF-8区域设置运行。如果失败,它将尝试en_US.UTF-8。如果这两个都失败,则模块将失败。

另请参见

另请参见

C(ansible-galaxy) 命令手册页

命令的手册页。

示例

---
- name: Install collection community.network
  community.general.ansible_galaxy_install:
    type: collection
    name: community.network

- name: Install role at specific path
  community.general.ansible_galaxy_install:
    type: role
    name: ansistrano.deploy
    dest: /ansible/roles

- name: Install collections and roles together
  community.general.ansible_galaxy_install:
    type: both
    requirements_file: requirements.yml

- name: Force-install collection community.network at specific version
  community.general.ansible_galaxy_install:
    type: collection
    name: community.network:3.0.2
    force: true

返回值

常见的返回值已在此处记录,以下是此模块特有的字段

描述

dest

字符串

dest参数的值。

返回:始终返回

force

布尔值

force参数的值。

返回:始终返回

installed_collections

字典

如果指定了requirements_file,则返回包含每个路径下所有已安装集合的字典。

如果指定了name,则返回每个路径下已安装的集合名称及其版本。

返回:安装集合时始终返回

示例:{"/custom/ansible/ansible_collections": {"community.general": "3.1.0"}, "/home/az/.ansible/collections/ansible_collections": {"community.docker": "1.6.0", "community.general": "3.0.2"}}

<path>

字典

该路径下的集合及其版本

返回:成功

installed_roles

字典

如果指定了requirements_file,则返回包含每个路径下所有已安装角色的字典。

如果指定了name,则返回每个路径下已安装的角色名称及其版本。

返回:安装角色时始终返回

示例:{"/custom/ansible/roles": {"ansistrano.deploy": "3.8.0"}, "/home/user42/.ansible/roles": {"ansistrano.deploy": "3.9.0", "baztian.xfce": "v0.0.3"}}

<path>

字典

该路径下的角色及其版本。

返回:成功

name

字符串

name参数的值。

返回:始终返回

new_collections

字典

此模块安装的新集合。

返回:成功

示例:{"community.docker": "1.6.1", "community.general": "3.1.0"}

new_roles

字典

此模块安装的新角色。

返回:成功

示例:{"ansistrano.deploy": "3.8.0", "baztian.xfce": "v0.0.3"}

requirements_file

字符串

requirements_file参数的值。

返回:始终返回

type

字符串

type参数的值。

返回:始终返回

version

字符串

在 community.general 10.0.0 中添加

ansible-galaxy 的 ansible-core 版本。

返回:始终返回

示例:"2.17.4"

作者

  • Alexei Znamensky (@russoz)