Execution
Date 12 Sep 2024 10:03:32 +0100
Duration 00:00:00.33
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
0 Hosts
0 Tasks
0 Results
1 Plays
6 Files
0 Records

File: /home/ssh-gateway/ansible/projects/RM9718/RM9718-cron-install.yaml

---
- name: Playbook to install the random crons
  hosts: all
  gather_facts: false
  roles:
    - plesk
  tasks:
    - name: On plesk server check for imunify
      ansible.builtin.shell: |
        set -o pipefail
        imunify360-agent version
      args:
        executable: /bin/bash
      register: imun_out
      failed_when: imun_out.rc != 0 and "command not found" not in imun_out.stderr
      changed_when: false
      ignore_errors: true

    - name: If imunify is installed install and run script
      when: imun_out.stdout is match('^\\d+\\.\\d+\\.\\d+')
      block:
        - name: Upload the script
          ansible.builtin.slurp:
            src: /home/ssh-gateway/ansible/projects/RM9718/setup_random_cron.sh
          delegate_to: 127.0.0.1
          register: file_contents

        - name: Execute the script
          ansible.builtin.shell: |
            set -o pipefail
            echo -e "{{ file_contents.content }}" | base64 -d > /tmp/setup_random_cron.sh
            chmod 755 /tmp/setup_random_cron.sh
            /tmp/setup_random_cron.sh
            rm -f /tmp/setup_random_cron.sh
          args:
            executable: /bin/bash
          changed_when: false

    - name: Print error message when imunify360-agent is not found
      when: imun_out.rc == 127 or "command not found" in imun_out.stderr
      ansible.builtin.debug:
        msg: "Error: imunify360-agent command not found, skipping the rest of the steps..."