community.general.pacman 模块 – 使用 pacman 管理软件包

注意

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

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

要安装它,请使用:ansible-galaxy collection install community.general

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

概要

  • 使用 pacman 软件包管理器管理软件包,该管理器由 Arch Linux 及其变体使用。

参数

参数

注释

executable

字符串

在 community.general 3.1.0 中添加

要使用的二进制文件的路径。这可以是 pacman 或与 pacman 兼容的 AUR 助手。

遗憾的是,Pacman 的兼容性定义不明确,特别是,此模块广泛使用 --print-format 指令,已知某些 AUR 助手(特别是 yay)未实现该指令。

请注意,AUR 助手的行为可能不符合预期,因此不建议使用。

默认值: "pacman"

extra_args

字符串

强制执行 state 时传递给 pacman 的其他选项。

默认值: ""

force

布尔值

删除软件包时,强制删除它们,而不进行任何检查。与 extra_args="--nodeps --nodeps" 相同。

当与 update_cache 结合使用时,强制刷新所有软件包数据库。与 update_cache_extra_args="--refresh --refresh" 相同。

选项

  • false ←(默认)

  • true

name

别名:package,pkg

列表 / 元素=字符串

要安装、升级或删除的软件包或文件的名称或名称列表。不能与 upgrade 结合使用。

reason

字符串

在 community.general 5.4.0 中添加

要为软件包设置的安装原因。

选项

  • "dependency"

  • "explicit"

reason_for

字符串

在 community.general 5.4.0 中添加

所有 软件包或仅为 软件包设置安装原因。

state=latest 的情况下,已安装的软件包如果将更新到较新版本,则不计为

选项

  • "all"

  • "new" ←(默认)

remove_nosave

布尔值

在 community.general 4.6.0 中添加

删除软件包时,不要将修改后的配置文件另存为 .pacsave 文件。(将 --nosave 传递给 pacman)

选项

  • false ←(默认)

  • true

state

字符串

是否安装(presentinstalledlatest),或者删除(absentremoved)软件包。

presentinstalled 将简单地确保安装了所需的软件包。

如果指定的软件包不是最新的可用版本,latest 将更新该软件包。

absentremoved 将删除指定的软件包。

选项

  • "absent"

  • "installed"

  • "latest"

  • "present" ←(默认)

  • "removed"

update_cache

布尔值

是否刷新主软件包列表。

这可以作为软件包安装的一部分运行,也可以作为单独的步骤运行。

如果未指定,则默认为 false

请注意,只有在 community.general 5.0.0 之前的版本中未指定 nameupgrade 时,此选项才会影响模块的 changed 状态。请参阅示例,了解如何保持旧的行为。

选项

  • false

  • true

update_cache_extra_args

字符串

在强制执行 update_cache 时,要传递给 pacman 的其他选项。

默认值: ""

upgrade

布尔值

是否升级整个系统。不能与 name 结合使用。

如果未指定,则默认为 false

选项

  • false

  • true

upgrade_extra_args

字符串

在强制执行 upgrade 时,要传递给 pacman 的其他选项。

默认值: ""

属性

属性

支持

描述

check_mode

支持:完全

可以在 check_mode 中运行,并返回更改状态预测,而无需修改目标。

diff_mode

支持:完全

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

注意事项

注意

  • 当与 loop: 一起使用时,每个软件包都将单独处理。将列表直接传递给 name 选项效率更高。

  • 要使用 AUR 助手(executable 选项),可能需要预先执行一些额外的设置步骤。例如,可能需要一个具有安装软件包权限的专用构建用户。

  • 在测试中,当使用 yay 作为 executable 选项时,该模块无法安装 AUR 软件包,并出现错误:error: target not found: <pkg>

示例

- name: Install package foo from repo
  community.general.pacman:
    name: foo
    state: present

- name: Install package bar from file
  community.general.pacman:
    name: ~/bar-1.0-1-any.pkg.tar.xz
    state: present

- name: Install package foo from repo and bar from file
  community.general.pacman:
    name:
      - foo
      - ~/bar-1.0-1-any.pkg.tar.xz
    state: present

- name: Install package from AUR using a Pacman compatible AUR helper
  community.general.pacman:
    name: foo
    state: present
    executable: yay
    extra_args: --builddir /var/cache/yay

- name: Upgrade package foo
  # The 'changed' state of this call will indicate whether the cache was
  # updated *or* whether foo was installed/upgraded.
  community.general.pacman:
    name: foo
    state: latest
    update_cache: true

- name: Remove packages foo and bar
  community.general.pacman:
    name:
      - foo
      - bar
    state: absent

- name: Recursively remove package baz
  community.general.pacman:
    name: baz
    state: absent
    extra_args: --recursive

- name: Run the equivalent of "pacman -Sy" as a separate step
  community.general.pacman:
    update_cache: true

- name: Run the equivalent of "pacman -Su" as a separate step
  community.general.pacman:
    upgrade: true

- name: Run the equivalent of "pacman -Syu" as a separate step
  # Since community.general 5.0.0 the 'changed' state of this call
  # will be 'true' in case the cache was updated, or when a package
  # was updated.
  #
  # The previous behavior was to only indicate whether something was
  # upgraded. To keep the old behavior, add the following to the task:
  #
  #   register: result
  #   changed_when: result.packages | length > 0
  community.general.pacman:
    update_cache: true
    upgrade: true

- name: Run the equivalent of "pacman -Rdd", force remove package baz
  community.general.pacman:
    name: baz
    state: absent
    force: true

- name: Install foo as dependency and leave reason untouched if already installed
  community.general.pacman:
    name: foo
    state: present
    reason: dependency
    reason_for: new

- name: Run the equivalent of "pacman -S --asexplicit", mark foo as explicit and install it if not present
  community.general.pacman:
    name: foo
    state: present
    reason: explicit
    reason_for: all

返回值

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

描述

cache_updated

布尔值

在 community.general 4.6.0 中添加

pacman -Sy 的更改状态。

当在 update_cache=true 旁边指定 nameupgrade=true 时非常有用。

返回:成功,当 update_cache=true

示例: false

packages

列表 / 元素=字符串

已更改的软件包列表。

在 community.general 4.5.0 之前,只有在 upgrade=true 时才返回此值。在 community.general 4.5.0 中,当软件包列表为空时,有时会省略此值,但是自 community.general 4.6.0 起,当指定 nameupgrade=true 时,始终返回此值。

返回:成功,并且指定 nameupgrade=true

示例: ["package", "other-package"]

stderr

字符串

在 community.general 4.1.0 中添加

来自 pacman 的错误输出。

返回:成功,当需要时

示例: "warning: libtool: local (2.4.6+44+gb9b44533-14) is newer than core (2.4.6+42+gb88cebd5-15) warning ..."

stdout

字符串

在 community.general 4.1.0 中添加

来自 pacman 的输出。

返回:成功,当需要时

示例: ":: Synchronizing package databases...  core is up to date :: Starting full system upgrade..."

作者

  • Indrajit Raychaudhuri (@indrajitr)

  • Aaron Bull Schaefer (@elasticdog)

  • Maxime de Roucy (@tchernomax)

  • Jean Raby (@jraby)