Thanks Zolvaring ,

Took input from the file & now output is coming in string format with 
following command ---
Now , Requires formatting of the output to a list .  

"ansible-playbook test.yml -e INV_FILE=latest123.yaml"

test.yml 
---
- hosts: 127.0.0.1
  connection: local
  tasks:

    - name: Print
      set_fact:
        your_fact: "{{ lookup('file', INV_FILE) }}"

    - name: Demonstrate
      debug:
        msg: "{{ your_fact }}"

===============================================

& Output gives values in string format 

TASK [Demonstrate] 
**************************************************************************************************************************************************************************************************************************
ok: [127.0.0.1] => {
    "msg": "---\n- releases:\n    gotcha:\n      file_name: gtp.tar\n      
md5: 11f6987275613ca3ecf832ea59c1\n      product_name: gotcha\n      
product_number: GTP 8881\n      release_candidate: rc19\n      version: 
19.0.0\n    tp:\n      file_name: tpr.tar\n      md5: 
ebd7742ed8fff0472733c0cd8e\n      product_name: tp\n      product_number: 
TTP 8057\n      release_candidate: rc25\n      version: 25.0.0\n    
device_name:\n      file_name: dna.tar\n      md5: 
e464e69a07123de075778aa9b7\n      product_name: device_name\n      
product_number: DNP 6746\n      release_candidate: rc25\n      version: 
25.0.0\n    abc:\n      file_name: abc.tar.gz\n      md5: 
94d992844322a05e9f4bec250f\n      product_name: abc\n      product_number: 
None\n      release_candidate: rc24\n      version: Raka_24_A\n    
adaptor:\n      file_name: aap.tar\n      md5: 84f75908bac48ddaae564e63\n  
    product_name: adaptor\n      product_number: apt 7815\n      
release_candidate: rc25\n      version: 25.1.1\n    trai:\n      file_name: 
trai.tar\n      md5: d992f1a34320f0590b52f69\n      product_name: trai\n    
  product_number: trp 6290\n      release_candidate: rc23\n      version: 
23.2.0\n    prxy:\n      file_name: prp.tar\n      md5: 
dc345ef912779f6f2be252a79\n      product_name: prxy\n      product_number: 
ppp 903\n      release_candidate: rc26\n      version: 26.0.1\n    luc:\n  
    file_name: lxp.tar\n      md5: 96f0e6f9ba753978e19d393cb\n      
product_name: luc\n      product_number: lxp 7686\n      release_candidate: 
RC26\n      version: 26.2.0\n    west:\n      file_name: wxp.tar\n      
md5: 048e15e3717be5302471ccb83\n      product_name: west\n      
product_number: wxp 8347\n      release_candidate: rc26\n      version: 
26.1.1\n    world:\n      file_name: wxp1.tar\n      md5: 
dbb86bf189bdb39b3f7a66150\n      product_name: world\n      product_number: 
wld 6384\n      release_candidate: rc24\n      version: 24.0.0\n    
breaking:\n      file_name: brp.tar\n      md5: 
051656275ed763b34c8de98de\n      product_name: breaking\n      
product_number: brp 8059\n      release_candidate: RC25\n      version: 
25.0.0\n    bad:\n      file_name: bdp.tar\n      md5: 
2f163c117e5bfaa7d5b7700d8\n      product_name: bad\n      product_number: 
bdp 8056\n      release_candidate: rc25\n      version: 25.0.0\n    
flash:\n      file_name: dc.tar\n      md5: ee811c2e6f434e190aec46f\n      
product_name: flash\n      product_number: fls 902 \n      
release_candidate: RC24\n      version: 24.0.0\n    arrow:\n      
file_name: arr.tar\n      md5: 4e5ba127475c6242491a2cb1\n      
product_name: arrow\n      product_number: aro 7655\n      
release_candidate: rc25\n      version: 25.0.0\n    legends:\n      
file_name: lxr.tar\n      md5: 9f2dbed641703a75dc88ffc0\n      
product_name: legends\n      product_number: lxr 6291\n      
release_candidate: rc18\n      version: 18.0.0\n    zoom:\n      file_name: 
zxp.tar\n      md5: ba3cd0da6e81df20afce3e2\n      product_name: zoom\n    
  product_number: zxp 7801\n      release_candidate: rc25\n      version: 
25.0.0\n    savitar:\n      file_name: sav.tar\n      md5: 
666c7b470e47a3\n      product_name: savitar\n      product_number: CXP 
5110\n      release_candidate: RC23\n      version: 23.0.0\n    
scarlett:\n      file_name: sxp228.tar\n      md5: 
151127dfa1f5a335dd3052d1\n      product_name: scarlet\n      
product_number: sxp 6292\n      release_candidate: rc18\n      version: 
18.0.0"
}
 

========================================================================================





On Tuesday, September 3, 2019 at 11:08:53 AM UTC+5:30, Zolvaring wrote:
>
> I think what you want to do to use cli is specify the path as your var 
> name just like your example, and then in your code when you invoke the 
> variable, use the file lookup:
>
> - set_fact:
>     your_fact: "{{ lookup('file', INV_VAR) }}"
>
> I'm not clear if you will need to do something beyond that for it to 
> naturally interpret the yaml object though there's a chance you'll still 
> end up with a string.
>
>
>
> On Mon, Sep 2, 2019, 4:09 PM Pawan Kumar <[email protected] <javascript:>> 
> wrote:
>
>> My Ansible code works fine , if i call dictionary values from file . 
>>
>> But requires guidance , how using the yaml file to pass as argument as 
>> INV file command line to execute playbook:
>>
>> something like :
>>
>> "ansible-playbook test.yml -e INV_FILE=latest123.yaml"
>>
>> On Tuesday, September 3, 2019 at 4:31:37 AM UTC+5:30, Pawan Kumar wrote:
>>>
>>> Hi Dick,
>>>
>>> Thanks for replying . 
>>>
>>> Well said , i was working with Ansible to parse values from dictionary 
>>> file . 
>>>
>>> working with the following ansible playbook 
>>>
>>>
>>>
>>> ---
>>> - hosts: 127.0.0.1
>>>   connection: local
>>>   vars_files:
>>>     - latest123.yaml
>>>   tasks:
>>>
>>>     - name: Printing "releases" value from yaml file...
>>>       debug:
>>>         msg: "Name of the Product is {{ releases[item]['product_name'] 
>>> }}  it's release candidate: {{ releases[item]['release_candidate'] }} & 
>>> version: {{ releases[item]['version'] }}"
>>>       with_items: "{{ releases.keys() }}"
>>>
>>>
>>>
>>>
>>> from the following latest123.yaml file 
>>>
>>>
>>> ---
>>> - releases:
>>>     gotcha:
>>>       file_name: gtp.tar
>>>       md5: 11f6987275613ca3ecf832ea59c1
>>>       product_name: gotcha
>>>       product_number: GTP 8881
>>>       release_candidate: rc19
>>>       version: 19.0.0
>>>     tp:
>>>       file_name: tpr.tar
>>>       md5: ebd7742ed8fff0472733c0cd8e
>>>       product_name: tp
>>>       product_number: TTP 8057
>>>       release_candidate: rc25
>>>       version: 25.0.0
>>>     device_name:
>>>       file_name: dna.tar
>>>       md5: e464e69a07123de075778aa9b7
>>>       product_name: device_name
>>>       product_number: DNP 6746
>>>       release_candidate: rc25
>>>       version: 25.0.0
>>>
>>>
>>>
>>>
>>> On Tuesday, September 3, 2019 at 4:06:16 AM UTC+5:30, Dick Visser wrote:
>>>>
>>>> Hi
>>>>
>>>> Kindly explain where ansible comes into play in this story?
>>>>
>>>> On Tue, 3 Sep 2019 at 00:18, Pawan Kumar <[email protected]> wrote:
>>>>
>>>>> Using Python script  to access values from yaml dictionary & print 
>>>>> some of the values as list . 
>>>>>
>>>>> For Example -  Parse the each key and extract the “product_name”, 
>>>>> “release_candidate” and “version“ & Print results as list
>>>>>
>>>>> The yaml file looks like 
>>>>>
>>>>>
>>>>>
>>>>> - releases:
>>>>>     - gotcha:
>>>>>         file_name: gtp.tar
>>>>>         md5: 11f6987275613ca3ecf832ea59c1
>>>>>         product_name: gotcha
>>>>>         product_number: GTP 8881
>>>>>         release_candidate: rc19
>>>>>         version: 19.0.0
>>>>>     - tp:
>>>>>         file_name: tpr.tar
>>>>>         md5: ebd7742ed8fff0472733c0cd8e
>>>>>         product_name: tp
>>>>>         product_number: TTP 8057
>>>>>         release_candidate: rc25
>>>>>         version: 25.0.0
>>>>>
>>>>> -- 
>>>>> 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 view this discussion on the web visit 
>>>>> https://groups.google.com/d/msgid/ansible-project/cdcb12c4-b6f6-4dbb-be42-b781e7d576d3%40googlegroups.com
>>>>>  
>>>>> <https://groups.google.com/d/msgid/ansible-project/cdcb12c4-b6f6-4dbb-be42-b781e7d576d3%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>>> .
>>>>>
>>>> -- 
>>>> Sent from a mobile device - please excuse the brevity, spelling and 
>>>> punctuation.
>>>>
>>> -- 
>> 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] <javascript:>.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/ansible-project/486f2e57-bed0-4a07-a841-81d090665633%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/ansible-project/486f2e57-bed0-4a07-a841-81d090665633%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/fc3e89c0-6455-461d-8ec3-b651a1752596%40googlegroups.com.

Reply via email to