I am using Ansible to upgrade Jenkins to a particular version. But before the installation, I will like to check for an existing jenkins version and uninstall it before proceeding with a new installation or upgrade. Below is the relevant code.
- name: Uninstall Jenkins
yum:
name: jenkins-2.107.2-1.1.noarch.rpm
state: absent
My current solution to uninstall the version is to 'hard code' it but that is not a dynamic solution since the version maybe different from server to server. How do i dynamically retrieve the jenkins rpm version if it exists and subsequently uninstall it using Ansible.
With ansible you describe a desired state, so uninstallation is not necessary. Just use in you playbook to install oder update to the latest version of jenkins:
- name: Install or Update Jenkins
yum:
name: jenkins
state: present
So if you really want to do an uninstall do it with:
- name: Uninstall Jenkins
yum:
name: jenkins
state: absent