Execution
Date 23 May 2025 11:23:13 +0100
Duration None
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
2 Hosts
6 Tasks
5 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: no
  vars:
    local_file_dir: "fetched_files"
    remote_dest_path: "/usr/local/psa/admin/conf/panel.ini"

  tasks:
    - name: Show current working directory
      ansible.builtin.shell: pwd
      register: current_pwd
      delegate_to: localhost
      run_once: true

    - name: Debug - current working directory
      ansible.builtin.debug:
        msg: "Current working directory: {{ current_pwd.stdout }}"

    - 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
      delegate_to: localhost
      run_once: true

    - name: Debug - list all matched files
      ansible.builtin.debug:
        msg: "Matched files: {{ found_ini_files.files | map(attribute='path') | list }}"

    - 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 }}"
        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 }}"