title: ansible assign a fact value to a variable
body: <p>I am new to ansible, I am writing a small playbook where it has to collect the fact value from the destination host and use that as a variable within the play. Can someone help me how to do that.</p>
  
  <pre><code>---
  - hosts: all
    gather_facts: True
    become: true
    become_method: sudo
    become_user: root
    vars:
      BUILD_PATH: /opt/services/dev
  
  
    pre_tasks:
     - setup:
        filter: ansible_env
     - set_fact:
         tag: "{{ ansible_env.DATA_AGGREGATOR_ENV }}"
     - debug: var=ENV
  
    tasks:
      - name: Copy to Build to DATA
        shell: cp -pr {{ BUILD_PATH }} {{ ENV }}
  </code></pre>
  
  <p>Note: DATA_AGGREGATOR_ENV is environmental variable defined in all servers and the value vary from one server to other.      </p>