# reading from files

**URL:** <https://forum.ansible.com/t/reading-from-files/26258>\
**Category:** Ansible Project\
**Created:** [December 12, 2017, 6:28am UTC](https://forum.ansible.com/t/reading-from-files/26258 "2017-12-12T06:28:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![coach.rhca](https://avatars.discourse-cdn.com/v4/letter/c/c57346/32.png) [@coach.rhca](https://forum.ansible.com/u/coach.rhca)\
**Post date:** [December 12, 2017, 6:28am UTC](https://forum.ansible.com/t/reading-from-files/26258/1 "2017-12-12T06:28:53Z")

</div>

Hi,

Trying to read the values from flat files and to use it as a variables in the ansible playbook , for example

the flatfile is  
#cat output

[example.com/development/testcaseone:v99](http://example.com/development/testcaseone:v99)

I want to use above values as a variables in the playbook , just like

---

<div class="post-metadata">

**Author:** ![coach.rhca](https://avatars.discourse-cdn.com/v4/letter/c/c57346/32.png) [@coach.rhca](https://forum.ansible.com/u/coach.rhca)\
**Post date:** [December 12, 2017, 6:30am UTC](https://forum.ansible.com/t/reading-from-files/26258/2 "2017-12-12T06:30:35Z")

</div>

just to add the flatfile is on a remote machine…

---

<div class="post-metadata">

**Author:** ![coach.rhca](https://avatars.discourse-cdn.com/v4/letter/c/c57346/32.png) [@coach.rhca](https://forum.ansible.com/u/coach.rhca)\
**Post date:** [December 12, 2017, 4:36pm UTC](https://forum.ansible.com/t/reading-from-files/26258/3 "2017-12-12T16:36:41Z")

</div>

i am trying to use the shell: cat testfile |sed ‘s///\n/g’ and got the values in column wise ,could you please help as how i can get this values individually using register.

---

<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:** [December 12, 2017, 5:34pm UTC](https://forum.ansible.com/t/reading-from-files/26258/4 "2017-12-12T17:34:30Z")

</div>

Not tested but something like this might work.

&nbsp;&nbsp;- fetch:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;src: /path/to/file  
&nbsp;&nbsp;&nbsp;&nbsp;register: r

&nbsp;&nbsp;- set\_fact:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rt1: '{{ (r.content | b64decode).split('/')[0] }}'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;stage\_name: '{{ (r.content | b64decode).split('/')[1] }}'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;job\_name: '{{ (r.content | b64decode).split('/')[2].split(':')[0] }}'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;version\_number: '{{ (r.content | b64decode).split('/')[2].split(':')[1] }}'

---

<div class="post-metadata">

**Author:** ![coach.rhca](https://avatars.discourse-cdn.com/v4/letter/c/c57346/32.png) [@coach.rhca](https://forum.ansible.com/u/coach.rhca)\
**Post date:** [December 13, 2017, 7:42am UTC](https://forum.ansible.com/t/reading-from-files/26258/5 "2017-12-13T07:42:18Z")

</div>

Thanks Kai for the help always…will check on this …
