title: Ansible - use delegate_to and access environment variable from delegated host
body: <p>I'm trying to look for a text pattern in a load balancer host from a worker host, using the following:</p>
  
  <pre><code>- name: A play
    hosts: workers
    tasks:
      - name: Look for text pattern in delegated host
        delegate_to: load-balancer-host
        find:
          paths: "$ENVIRONMENT_VARIABLE/subdir"
          file_type: file
          patterns: file.pattern
          contains: 'text pattern'
        register: aVariable
  </code></pre>
  
  <p>The problem is that I can't found any way to make $ENVIRONMENT_VARIABLE (this variable exists in the load-balancer-host) available for the play (it contains the directory, in load-balancer-host, from where I want to look for). ansible_env is only available for the workers but not for the load-balancer-host</p>
  
  <p>I have tried...</p>
  
  <pre><code>- name: A play
    hosts: workers
    tasks:
      - name: set fact
        set_fact:
          env_var: "{{ lookup('env', 'ENVIRONMENT_VARIABLE') }}"
        delegate_to: load-balancer-host
  
      - name: debug
        debug:
          msg: "{{ env_var }}"
  </code></pre>
  
  <p>... too, but it prints an empty string.</p>