Execution
Date 23 May 2025 14:02:02 +0100
Duration 00:04:51.88
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
330 Hosts
7 Tasks
2301 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: Show current working directory
      ansible.builtin.shell: pwd
      register: current_pwd
      delegate_to: localhost
      run_once: true
      changed_when: false

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

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

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

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

    - 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'
        owner: root
        group: root
        force: true
      notify: Show success message

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