Execution
Date 11 Sep 2024 15:44:44 +0100
Duration None
Controller ssh-gw-4.layershift.com
User root
Versions
Ansible 2.16.4
ara 1.7.1 / 1.7.1
Python 3.10.10
Summary
0 Hosts
1 Tasks
0 Results
1 Plays
6 Files
0 Records

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

---
- name: Update layershift mysql config
  hosts: all
  gather_facts: false
  roles:
    - plesk
  tasks:
    - name: Run update on plesk
      when: plesk_found
      block:
        - name: Set files to upload
          ansible.builtin.set_fact:
            files_to_upload:
              - /home/ssh-gateway/ansible/kuly/files/layershift-default.cnf
        - name: Upload the files
          ansible.builtin.copy:
            src: "{{ item }}"
            dest: "/tmp/{{ item | basename }}"
            mode: '0644'
            owner: root
            group: root
          loop: "{{ files_to_upload }}"
        - name: Move uploaded files
          ansible.builtin.shell: |
            set -o pipefail
            chattr -i /etc/layershift-default.cnf
            rm -f /etc/layershift-default.cnf
            mv /tmp/{{ item | basename }} /etc/
            chattr +i /etc/layershift-default.cnf
          loop: "{{ files_to_upload }}"
          changed_when: true
        - name: Restart mariadb
          ansible.builtin.systemd_service:
            name: mariadb.service
            state: restarted
        - name: Check if started
          ansible.builtin.shell: |
            set -o pipefail
            service_time=$(systemctl show -p ActiveEnterTimestamp mariadb.service | awk -F'=' '{print $2}')
            service_epoch=$(date -d "$service_time" +%s)
            current_time=$(date +%s)
            time_diff=$((current_time - service_epoch))
            echo $time_diff
          args:
            executable: /bin/bash
          register: time_difference_output
          changed_when: false
        - name: Determine if service was restarted recently
          ansible.builtin.debug:
            msg: "Service was restarted recently."
          when: time_difference_output.stdout | int > 1 and time_difference_output.stdout | int < 300
        - name: Get services status
          ansible.builtin.service_facts:
        - name: See the status
          ansible.builtin.debug:
            msg: 'Service status is: {{ ansible_facts.services["mariadb.service"].state }}'
        - name: Write to a file the failed one
          when: '"running" not in ansible_facts.services["agent360.service"].state'
          ansible.builtin.lineinfile:
            path: /home/ssh-gateway/ansible/kuly/stopped.txt
            create: true
            mode: '0644'
            line: '{{ inventory_hostname }} is not running'
          delegate_to: localhost