title: Ansible set_fact array and populate it from in loop
body: <p>I want to create an array and insert value from the the array <code>IP_TO_DNS</code> to reversed IP address.</p>
  
  <p>The idea is to restructure the IP address given in the argument to be matchable later in my code.</p>
  
  <p><strong>Code</strong></p>
  
  <pre><code>- name: create array reversed
    set_fact: reversed_ip=[]
  
  - name: set convert ips from cli to matchable reversed ip
    set_fact: reversed_ip='{{ item | regex_replace('^(?P&lt;first_range&gt;\d{1,3})\.(?P&lt;second_range&gt;\d{1,3})\.(?P&lt;third_range&gt;\d{1,3})\.', 'named.\\g&lt;third_range&gt;.\\g&lt;second_range&gt;.\\g&lt;first_range&gt;')}}'
    with_items: '{{IP_TO_DNS}}'
  
  - name: Match first block of results in path name
    debug: var=item
    with_items: '{{reversed_ip}}'
  </code></pre>
  
  <p><strong>Output</strong></p>
  
  <pre><code>TASK [dns : set convert ips from cli to matchable reversed ip] *****************
  ok: [10.1.10.5] =&gt; (item=10.1.10.1)
  ok: [10.1.10.5] =&gt; (item=10.1.10.2)
  ok: [10.1.10.5] =&gt; (item=10.1.10.3)
  
  TASK [dns : Match first block of results in path name] *************************
  ok: [10.1.10.5] =&gt; (item=named.10.1.103) =&gt; {
      "item": "named.10.1.103"
  }
  </code></pre>
  
  <p>It look like my variable is not set as an array and only the first value is populate.</p>
  
  <p>Any ideas ? </p>