title: Ansible: How to loop set_fact varaibles
body: <p>i have a ansible-playbook that generates all elements output from remote server, and being saved into variables using set_fact.
  i want to try and write each output into separate files using copy module with <code>loop</code>.</p>
  
  <p><code>set_fact</code> works to store the content but i am struggling to get them specified under <code>copy</code> module using loop.</p>
  
  <pre><code>- name: Playbook to get element details from server
    uri:
      url: https://10.10.10.19/rest/v1.1/nucli?SetType={{ item }}
      body_format: raw
      method: GET
      headers:
        Content-Type: application/xml
        Accept: application/xml
        Authorization: Bearer password
      return_content: yes
    register: fileout
    with_items:
       - My_var1
       - My_var2
       - My_var3
       - My_var4
  
  - set_fact:
      My_var1: "{{ fileout.results[0].content }}"
      My_var2: "{{ fileout.results[1].content }}"
      My_var3: "{{ fileout.results[2].content }}"
      My_var4: "{{ fileout.results[3].content }}"
  
  - copy:
       content: {{ item }}
       dest: "/users/ansible/vars/{{ item }}.txt"
    delegate_to: localhost
    loop:
       - My_var1
       - My_var2
       - My_var3
       - My_var4
  </code></pre>
  
  <p><code>Playbook execution:</code>
  all steps executed successfully. but in <code>copy</code> module <code>content: {{ item }}</code> is not using set_fact variables, instead they are just copying string My_var1... etc.</p>
  
  <p>Could anyone help me how to use loop for set_fact variable names? So that i can store the content that i have saved from set_fact <code>(example - My_var1: "{{ fileout.results[0].content }}" )</code></p>
  
  <p>Thanks in advance.</p>