apt_policy module – Get status of apt package

Note

This module is part of the ufrmath.computer_labs collection (version 1.0.0).

To install it, use: ansible-galaxy collection install git+https://github.com/guillod/computer_labs. You need further requirements to be able to use this module, see Requirements for details.

To use it in a playbook, specify: ufrmath.computer_labs.apt_policy.

New in ufrmath.computer_labs 1.0.0

Synopsis

  • Get status of a package through apt returning informations similar to the command apt-cache policy.

Requirements

The below requirements are needed on the host that executes this module.

  • python-apt (python 2)

  • python3-apt (python 3)

Parameters

Parameter

Comments

name

aliases: package, pkg

string / required

A package name, like foo.

Attributes

Attribute

Support

Description

check_mode

Support: full

Can run in check_mode and return changed status prediction without modifying target

diff_mode

Support: full

Will return details on what has changed (or possibly needs changing in check_mode), when in diff mode

platform

Platform: debian

Target OS/families that can be operated against

Examples

- name: Get status of libpam-systemd package
  ufrmath.computer_labs.apt_policy:
    name: libpam-systemd
  register: apt_status

- name: Display all versions
  debug:
    msg: "{{ apt_status.versions }}"

- name: Display installed version
  debug:
    msg: "{{ apt_status.installed }}"

- name: Check if installed version is from security
  debug:
    msg: "{{ apt_status.installed | json_query(query) | length > 0 }}"
  vars:
    query: "origins[?ends_with(archive,'-security')]"

- name: Check if a specific version is in security
  debug:
    msg: "{{ apt_status.versions | json_query(query) | length > 0 }}"
  vars:
    query: "[?version=='{{ version }}'].origins[] | [?ends_with(archive,'-security')]"
    version: "245.4-4ubuntu3.15"

Return Values

Common return values are documented here, the following are the fields unique to this module:

Key

Description

candidate

string

Candidate version together with their origins.

Returned: always

Sample: ""

installed

string

Installed version together with their origins.

Returned: always

Sample: ""

versions

list / elements=dictionary

List of versions together with their origins.

Returned: always

Sample: ""

Authors

  • Julien Guillod (@guillod)