| defaults | ||
| meta | ||
| tasks | ||
| .gitignore | ||
| LICENSE | ||
| README.md | ||
check_version Role
This role checks the installed version of a software against the latest available version on GitHub and sets a variable if an upgrade is required.
Description
The check_version role allows you to compare the installed version of a software with the latest version from a GitHub repository. It supports multiple methods to determine the installed version, providing flexibility for various use cases. If an upgrade is required, the variable do_upgrade is set.
Installation
- Ensure that Ansible is installed on your system. The recommended version is at least
2.17. - Clone this repository or add the role to your existing project.
- Make sure the following dependencies are available:
- Python with the
requestslibrary (for GitHub API calls) - Access to the GitHub API (optionally with a token for private repositories)
- Python with the
Variables
The role uses the following variables:
-
check_version_remote_version: A version number in the formatx.x.x. Example:3.3.0. -
check_version_github_repo: The GitHub repository in the formatuser/repo. Example:ansible/ansible. -
check_version_file_path: The path to the file containing the installed version. Example:/opt/software/version. -
check_version_deb_name(optional): The name of the Debian package to check the installed version. Example:nginx. -
check_version_command(optional): A shell command that returns the installed version. Example:nginx -v.
Output Variables
check_version_do_install: Boolean (true/false) – Indicates whether the software needs to be installed.check_version_do_upgrade: Boolean (true/false) – Indicates whether the installed version needs to be upgraded.check_version_local_version: String (x.x.x) – The currently installed version of the software.check_version_remote_version: String (x.x.x)* – The target version of the software to compare against (from an online source or manually set).
Usage
Example Playbook
- hosts: all
tasks:
- name: Check Version
ansible.builtin.include_role:
name: check_version
vars:
check_version_github_repo: "user/other_software"
check_version_file_path: "/opt/other_software/version"
- name: Upgrade xxx
when: check_version_do_upgrade | default(false)
block:
- name: Install xxx
when: check_version_do_install | default(false)
block:
Features
- Flexible Version Detection: Supports file, Debian package, or shell command methods.
- GitHub Integration: Uses the GitHub API to fetch the latest version.
- Upgrade Detection: Sets the
check_version_do_upgradevariable if an update is required. - Modular Design: Imports tasks based on the provided variables.
Contributing
Contributions are welcome! Please follow these steps:
- Fork the repository.
- Create a new branch for your changes.
- Submit a pull request describing your changes.
License
This project is licensed under the AGPL License. The AGPL license requires that modifications to the software be disclosed when distributed or made available over a network. For more information, see the LICENSE file.