Execution
Date 23 May 2025 11:19:57 +0100
Duration 00:00:01.22
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
1 Hosts
2 Tasks
2 Results
1 Plays
1 Files
0 Records

File: /home/ssh-gateway/ansible/kuly/upload_ini_to_hosts.yml

---
- name: Upload panel.ini files to each host in generated inventory
  hosts: all
  gather_facts: false
  vars:
    local_file_dir: "fetched_files"
    remote_dest_path: "/usr/local/psa/admin/conf/panel.ini"

  tasks:
    - name: Find matching ini file in local directories
      ansible.builtin.find:
        paths: "{{ local_file_dir }}"
        patterns: "{{ inventory_hostname }}-panel.ini"
        recurse: true
      register: found_ini_files

    - name: Fail if no matching .ini file is found
      ansible.builtin.assert:
        that:
          - found_ini_files.files | length == 1
        fail_msg: "Expected exactly one matching .ini file for {{ inventory_hostname }} but found {{ found_ini_files.files | length }}."

    - name: Upload the matched ini file to the remote host
      ansible.builtin.copy:
        src: "{{ found_ini_files.files[0].path }}"
        dest: "{{ remote_dest_path }}"
        owner: root
        group: root
        mode: '0644'
      notify: Validate file upload

    - name: Show success message
      ansible.builtin.debug:
        msg: "Uploaded {{ found_ini_files.files[0].path }} to {{ inventory_hostname }} at {{ remote_dest_path }}"

  handlers:
    - name: Validate file upload
      ansible.builtin.stat:
        path: "{{ remote_dest_path }}"
      register: uploaded_file
      until: uploaded_file.stat.exists
      retries: 5
      delay: 1

    - name: Debug file existence
      ansible.builtin.debug:
        msg: "File {{ remote_dest_path }} exists on {{ inventory_hostname }}: {{ uploaded_file.stat.exists }}"