On Tuesday, 12 December 2017 07.28.53 CET [email protected] wrote:
> 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..

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

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/2024833.PQvOlT6LQd%40x1.
For more options, visit https://groups.google.com/d/optout.

Reply via email to