check_latest_packages_version¶
About The Role¶
An Ansible role to check if latest version of a list of packages is installed.
Requirements¶
No requirements.
Dependencies¶
No dependencies.
Example Playbook¶
- hosts: localhost
  gather_facts: false
  vars:
    packages_list:
      - coreutils
      - wget
  roles:
    - check_latest_packages_version
License¶
Apache
Full Description¶
Role Documentation¶
Welcome to the ‘check_latest_packages_version’ role documentation.
Role Defaults¶
This section highlights all of the defaults and variables set within the ‘check_latest_packages_version’ role.
# List of packages to check.
# Empty list by default
packages_list: []
Molecule Scenarios¶
Molecule is being used to test the ‘check_latest_packages_version’ role. The following section highlights the drivers in service and provides an example playbook showing how the role is leveraged.
- Driver: podman:
 
Scenario: default¶
Molecule Platform(s)¶
- name: centos
  hostname: centos
  image: centos/centos:stream8
  registry:
    url: quay.io
  dockerfile: ../../../../../.config/molecule/Dockerfile
  pkg_extras: python*-setuptools python*-pyyaml
  volumes:
  - /etc/ci/mirror_info.sh:/etc/ci/mirror_info.sh:ro
  privileged: true
  environment:
    http_proxy: "{{ lookup('env', 'http_proxy') }}"
    https_proxy: "{{ lookup('env', 'https_proxy') }}"
  ulimits:
  - host
Molecule Inventory¶
hosts:
  all:
    hosts:
      centos:
        ansible_python_interpreter: /usr/bin/python3
Example default playbook¶
- name: Converge
  hosts: all
  tasks:
  - name: Run validation with empty package list
    block:
    - include_role:
        name: check_latest_packages_version
    rescue:
    - name: Clear host errors
      meta: clear_host_errors
    - debug:
        msg: |
          The validation fails due to an empty package list
          given as parameter.
  - name: Working Detection of Update for valfrwk-release package
    block:
    - include_role:
        name: check_latest_packages_version
      vars:
        packages_list:
        - valfrwk-release
    rescue:
    - name: Clear host errors
      meta: clear_host_errors
    - debug:
        msg: The validation has detected a new version!
  - name: Validate No Available Update for valfrwk-release rpm
    block:
    - name: Update valfrwk-release rpm to the latest one
      package:
        name: valfrwk-release
        state: latest
    - include_role:
        name: check_latest_packages_version
      vars:
        packages_list:
        - valfrwk-release
  - name: Working Detection of Update for an uninstalled package
    block:
    - include_role:
        name: check_latest_packages_version
      vars:
        packages_list:
        - whatchamacallit
    rescue:
    - name: Clear host errors
      meta: clear_host_errors
    - debug:
        msg: |
          The validation fails because 'whatchamacallit' rpm is not
          installed! End the playbook run
    - name: End play
      meta: end_play
  - name: Fail the test
    fail:
      msg: |
        The check_latest_packages_version role should have detected
        that packages have available updates.