reading from files

30 views
Skip to first unread message

coach...@gmail.com

unread,
Dec 12, 2017, 1:28:53 AM12/12/17
to Ansible Project
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

I want to use above values as a variables in the playbook , just like
---
- hosts:
  vars:
    rt1: example.com
    stage_name: development
    job_name: testcaseone
    version_number: v99


I tried with lookup ('file', /path/to/output) but it gives the entire output of the value..

thanks for the help..

coach rhca

unread,
Dec 12, 2017, 1:30:55 AM12/12/17
to ansible...@googlegroups.com
just to add the flatfile is on a remote machine...

--
You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/OipBBxJ_NNc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-project+unsubscribe@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/0dfc15cc-9ec2-4722-a04e-a4319cfcbc7a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

coach rhca

unread,
Dec 12, 2017, 11:36:57 AM12/12/17
to ansible...@googlegroups.com
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. 

Kai Stian Olstad

unread,
Dec 12, 2017, 12:35:03 PM12/12/17
to ansible...@googlegroups.com
Not tested but something like this might work.

- fetch:
src: /path/to/file
register: r

- set_fact:
rt1: '{{ (r.content | b64decode).split('/')[0] }}'
stage_name: '{{ (r.content | b64decode).split('/')[1] }}'
job_name: '{{ (r.content | b64decode).split('/')[2].split(':')[0] }}'
version_number: '{{ (r.content | b64decode).split('/')[2].split(':')[1] }}'


--
Kai Stian Olstad

coach rhca

unread,
Dec 13, 2017, 2:42:31 AM12/13/17
to ansible...@googlegroups.com
Thanks Kai for the help always..will check on this ...

--
You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/OipBBxJ_NNc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-project+unsubscribe@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages