# Extract data from task in a variable

**URL:** <https://forum.ansible.com/t/extract-data-from-task-in-a-variable/27457>\
**Category:** Ansible Project\
**Created:** [May 4, 2018, 1:06pm UTC](https://forum.ansible.com/t/extract-data-from-task-in-a-variable/27457 "2018-05-04T13:06:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bubul\_Medhi](https://avatars.discourse-cdn.com/v4/letter/b/90ced4/32.png) [@Bubul\_Medhi](https://forum.ansible.com/u/Bubul_Medhi)\
**Post date:** [May 4, 2018, 1:06pm UTC](https://forum.ansible.com/t/extract-data-from-task-in-a-variable/27457/1 "2018-05-04T13:06:43Z")

</div>

Hi,  
This is a role i wrote which will get the IP addresses of the Hosts and then copy a file from the ansible server to the host server.

- name: Seeking the host IP address  
shell: |  
ifconfig eth0 | grep “inet addr” | cut -d ‘:’ -f 2 | cut -d ’ ’ -f 1  
register: ipv4\_address

- debug: var=ipv4\_address.stdout\_lines

- name: Make the copy to CTM agents  
delegate\_to: 127.0.0.1  
shell: sshpass -p ‘xyz@123456’ scp /home/admin/schoolproject/deploy/Agent\_{{ipv4\_address.stdout\_lines}}.zip admin@{{ipv4\_address.stdout\_lines}}:/var/tmp/

After running it, I am getting the error below.

fatal: [10.200.2.6 → 127.0.0.1]: FAILED! =\> {“changed”: true, “cmd”: “sshpass -p ‘xyz@123456’ scp /home/admin/schoolproject/deploy/**Agent\_[u’10.200.2.6’].zip** admin@**[u’10.200.2.6’]**:/var/tmp/”, “delta”: “0:00:00.925109”, “end”: “2018-05-04 18:16:52.188862”, “msg”: “non-zero return code”, “rc”: 1, “start”: “2018-05-04 18:16:51.263753”, “stderr”: “ssh: Could not resolve hostname u10.200.2.6: Name or service not known\r\nlost connection”, “stderr\_lines”: [“ssh: Could not resolve hostname u10.200.2.6: Name or service not known”, “lost connection”], “stdout”: “”, “stdout\_lines”: }

How do I remove the quotes and square bracket **[u’]** from the variable ?

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [May 4, 2018, 4:07pm UTC](https://forum.ansible.com/t/extract-data-from-task-in-a-variable/27457/2 "2018-05-04T16:07:26Z")

</div>

You need to use ipv4\_address.stdout not ipv4\_address.stdout\_lines.

By the way, if you gather facts, which is the default, you already have the ip in the variable {{ ansible\_default\_ipv4.address }}
