community.general.pacman (8.5.0) — module

Manage packages with I(pacman)

Authors: Indrajit Raychaudhuri (@indrajitr), Aaron Bull Schaefer (@elasticdog) <aaron@elasticdog.com>, Maxime de Roucy (@tchernomax), Jean Raby (@jraby)

Install collection

Install with ansible-galaxy collection install community.general:==8.5.0


Add to requirements.yml

  collections:
    - name: community.general
      version: 8.5.0

Description

Manage packages with the I(pacman) package manager, which is used by Arch Linux and its variants.

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Install package foo from repo
  community.general.pacman:
    name: foo
    state: present
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Install package bar from file
  community.general.pacman:
    name: ~/bar-1.0-1-any.pkg.tar.xz
    state: present
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- 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
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- 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
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- 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
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Remove packages foo and bar
  community.general.pacman:
    name:
      - foo
      - bar
    state: absent
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Recursively remove package baz
  community.general.pacman:
    name: baz
    state: absent
    extra_args: --recursive
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Run the equivalent of "pacman -Sy" as a separate step
  community.general.pacman:
    update_cache: true
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Run the equivalent of "pacman -Su" as a separate step
  community.general.pacman:
    upgrade: true
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- 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
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Run the equivalent of "pacman -Rdd", force remove package baz
  community.general.pacman:
    name: baz
    state: absent
    force: true
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Install foo as dependency and leave reason untouched if already installed
  community.general.pacman:
    name: foo
    state: present
    reason: dependency
    reason_for: new
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- 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

Inputs

    
name:
    aliases:
    - package
    - pkg
    description:
    - Name or list of names of the package(s) or file(s) to install, upgrade, or remove.
      Cannot be used in combination with O(upgrade).
    elements: str
    type: list

force:
    default: false
    description:
    - When removing packages, forcefully remove them, without any checks. Same as O(extra_args="--nodeps
      --nodeps").
    - When combined with O(update_cache), force a refresh of all package databases. Same
      as O(update_cache_extra_args="--refresh --refresh").
    type: bool

state:
    choices:
    - absent
    - installed
    - latest
    - present
    - removed
    default: present
    description:
    - Whether to install (V(present) or V(installed), V(latest)), or remove (V(absent)
      or V(removed)) a package.
    - V(present) and V(installed) will simply ensure that a desired package is installed.
    - V(latest) will update the specified package if it is not of the latest available
      version.
    - V(absent) and V(removed) will remove the specified package.
    type: str

reason:
    choices:
    - dependency
    - explicit
    description:
    - The install reason to set for the packages.
    type: str
    version_added: 5.4.0
    version_added_collection: community.general

upgrade:
    description:
    - Whether or not to upgrade the whole system. Cannot be used in combination with O(name).
    - If not specified, it defaults to V(false).
    type: bool

executable:
    default: pacman
    description:
    - Path of the binary to use. This can either be C(pacman) or a pacman compatible AUR
      helper.
    - Pacman compatibility is unfortunately ill defined, in particular, this modules makes
      extensive use of the C(--print-format) directive which is known not to be implemented
      by some AUR helpers (notably, C(yay)).
    - Beware that AUR helpers might behave unexpectedly and are therefore not recommended.
    type: str
    version_added: 3.1.0
    version_added_collection: community.general

extra_args:
    default: ''
    description:
    - Additional option to pass to pacman when enforcing O(state).
    type: str

reason_for:
    choices:
    - all
    - new
    default: new
    description:
    - Set the install reason for V(all) packages or only for V(new) packages.
    - In case of O(state=latest) already installed packages which will be updated to a
      newer version are not counted as V(new).
    type: str
    version_added: 5.4.0
    version_added_collection: community.general

update_cache:
    description:
    - Whether or not to refresh the master package lists.
    - This can be run as part of a package installation or as a separate step.
    - If not specified, it defaults to V(false).
    - Please note that this option only had an influence on the module's C(changed) state
      if O(name) and O(upgrade) are not specified before community.general 5.0.0. See
      the examples for how to keep the old behavior.
    type: bool

remove_nosave:
    default: false
    description:
    - When removing packages, do not save modified configuration files as C(.pacsave)
      files. (passes C(--nosave) to pacman)
    type: bool
    version_added: 4.6.0
    version_added_collection: community.general

upgrade_extra_args:
    default: ''
    description:
    - Additional option to pass to pacman when enforcing O(upgrade).
    type: str

update_cache_extra_args:
    default: ''
    description:
    - Additional option to pass to pacman when enforcing O(update_cache).
    type: str

Outputs

cache_updated:
  description:
  - The changed status of C(pacman -Sy).
  - Useful when O(name) or O(upgrade=true) are specified next to O(update_cache=true).
  returned: success, when O(update_cache=true)
  sample: false
  type: bool
  version_added: 4.6.0
  version_added_collection: community.general
packages:
  description:
  - A list of packages that have been changed.
  - Before community.general 4.5.0 this was only returned when O(upgrade=true). In
    community.general 4.5.0, it was sometimes omitted when the package list is empty,
    but since community.general 4.6.0 it is always returned when O(name) is specified
    or O(upgrade=true).
  elements: str
  returned: success and O(name) is specified or O(upgrade=true)
  sample:
  - package
  - other-package
  type: list
stderr:
  description:
  - Error output from pacman.
  returned: success, when needed
  sample: 'warning: libtool: local (2.4.6+44+gb9b44533-14) is newer than core (2.4.6+42+gb88cebd5-15)
    warning ...'
  type: str
  version_added: 4.1.0
  version_added_collection: community.general
stdout:
  description:
  - Output from pacman.
  returned: success, when needed
  sample: ':: Synchronizing package databases...  core is up to date :: Starting full
    system upgrade...'
  type: str
  version_added: 4.1.0
  version_added_collection: community.general