Delegate_to play on awx

I have a playbook that copies files to remote hosts whose hostnames are dynamically derived in the playbook. if the play is run from the control node it works perfectly if I run from awx I get an error on the delegation

- name: Copy app to remote
  copy:
    src: '{{ path_local_to_deploy }}/{{ app_to_deploy }}'
    dest: '/tmp/{{ app_to_deploy }}'
    owner: root
    group: root
    mode: 0644
    remote_src: true
  delegate_to: mvlmgmt002.sidi.mpi.it
  become: true
  tags: action

I also tried using delegation on the control node but it fails to copy the files to the remote hosts but copies to /tmp of the control node

That would not be the /tmp of AWX machine but of the EE. Since you donā€™t mention or show the exact error Iā€™m going to assume it is related on how the /tmp dir is mounted and sized within the EE. I would suggest to use a mounted directory with plenty of space and adequate permissions from the AWX machine shared with the EE instead.

the file I have to copy is on the host node (mvlmgmt002.sidi.mpi.it) towards remote hosts defined by a dynamic inventory which is why I have to delegate the host node at the moment to understand I solved it in an unprofessional way with scp but it seems to work. ā€¦
Below is the workaround to better understand what the problem was

- name: --- Do redeploy ---
  hosts: "{{ groups['dynamic_hosts'] | default([]) }}"
  gather_facts: true
  vars_files:
    - ../../vault_vars/vault_secret.yml

  pre_tasks:
    - name: Debug app_to_deploy variable
      debug:
        msg: "app_to_deploy for host {{ inventory_hostname }}: {{ app_to_deploy }}"

    - name: SCP file to remote host with password
      ansible.builtin.expect:
        command: scp -o StrictHostKeyChecking=no /var/www/html/files/deploy/{{ app_to_deploy }} {{ ansible_ssh_user }}@{{ inventory_hostname }}:/tmp/{{ app_to_deploy }}
        responses:
          password: "{{ awx_ssh_user_pass }}"
      delegate_to: mvlmgmt002.sidi.mpi.it
      become: true
  
  roles:
    - role: new_redeploy_middleware

Iā€™m not sure how this would have worked with copy at all, it can only work from the controller to the target. You would have to be using ā€˜synchronizeā€™ ā€¦ which does not combine well with become.

Using scp might be the cleanest way to copy files between those 2 hosts. if you did not have direct access from the delegated host to target, you could use scp -3.

1 Like

Why donā€™t you include the error? It would make helping you easier.
If it was me, Iā€™d split this task in two: first use the module ā€œfetchā€ to get the file from mvlmgmt002 on the control node, and then copy to the destination machines.

I tried with fetch but does not workā€¦ the problem is the nested containers the delegate directive is complex to manageā€¦ another way was get_url but some ports on the vm are closedā€¦ at the moment I solved it with scp