Execution
Date 28 May 2025 11:24:07 +0100
Duration 00:01:22.64
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
389 Hosts
4 Tasks
768 Results
2 Plays
1 Files
0 Records

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

---
- name: Get latest agent360 version from GitHub
  hosts: localhost
  gather_facts: false
  strategy: linear
  vars:
    # Fallback version if GitHub fails
    latest_version: "1.3.3"
  tasks:
    - name: Get the latest version of agent360 from GitHub
      ansible.builtin.shell: |
        set -o pipefail
        latest=$(curl -sL https://api.github.com/repos/plesk/agent360/releases/latest  | jq -r ".tag_name" | sed 's/^v//')
        echo "$latest"
      args:
        executable: /bin/bash
      register: latest_version_out
      changed_when: false
      run_once: true

    - name: Set the latest_version fact globally
      ansible.builtin.set_fact:
        latest_version: "{{ latest_version_out.stdout }}"
      run_once: true

- name: Check if each host needs agent360 upgrade
  hosts: all
  gather_facts: false
  strategy: linear
  tasks:
    - 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 needing an upgrade
      when: ver_out.rc == 0 and ver_out.stdout < hostvars['localhost']['latest_version']
      ansible.builtin.lineinfile:
        path: /home/ssh-gateway/ansible/kuly/agent360_need_upgrade.txt
        create: true
        mode: '0644'
        line: '{{ inventory_hostname }} needs upgrade - version {{ ver_out.stdout }}'
      delegate_to: localhost