Execution
Date 16 Dec 2024 15:06:45 +0000
Duration 00:03:13.69
Controller ssh-gw-4.layershift.com
User root
Versions
Ansible 2.16.11
ara 1.7.2 / 1.7.2
Python 3.10.10
Summary
297 Hosts
4 Tasks
1167 Results
1 Plays
1 Files
0 Records

File: /home/ssh-gateway/ansible/kuly/agent360_check_version.yaml

---
- name: Check if there is a need to upgrade agent360
  hosts: all
  gather_facts: false
  vars:
    latest_version: ""
  tasks:
    - name: Get the latest version of agent360 from GitHub
      ansible.builtin.shell: |
        latest=$(curl -sL https://api.github.com/repos/plesk/agent360/releases/latest | jq -r ".tag_name" | sed 's/^v//')
        echo $latest
      register: latest_version_out
      changed_when: false

    - name: Set the latest_version variable
      set_fact:
        latest_version: "{{ latest_version_out.stdout }}"

    - name: Get installed version and compare
      ansible.builtin.shell: |
        set -o pipefail
        pip$(head -1  $(which agent360)| awk -F "python" '{print $2}') show agent360 | grep Version | awk '{ print $2 }'
      args:
        executable: /bin/bash
      register: ver_out
      changed_when: ver_out.rc != 0

    - name: Log the ones need updating
      when: ver_out.rc == 0 and ver_out.stdout < latest_version
      ansible.builtin.lineinfile:
        path: /home/ssh-gateway/ansible/kuly/agent360_need_upgrade.txt
        create: true
        mode: '0644'
        line: '{{ inventory_hostname }} need upgrade - version {{ ver_out.stdout }}'
      delegate_to: localhost