reading input from LibreOffice Calc .ods

Hi all,

Is it possible to get input from .ods and place it in playbook for execution?

Taking copy action for an example.

action: copy src=/home/celine/Desktop/fileA dest=/home/celine2/Desktop/fileB
^ ^
Instead of directly input “fileA” and “fileB”, can i read these from .ods spreadsheet? Suppose “fileA” is on spreadsheet cell number D22 and “fileB” is on E22.

Thank you.

Celine

You could write a lookup plugin that looked like this:

{{ lookup(“ods”, “foo.ods B22”) }}

For more information on lookup plugins see the “lookup_plugins” directory in the example source. How the “file” lookup plugin works is pretty basic, and you could see how to adapt it.

Hi Michael,

I have been looking up on how to write a lookup plugin for some time. But i am still getting to nowhere.

Can you give me some guidance on how to do it?

Thanks.

Can you tell me what you’ve tried so far and where you got stuck?

I found the lookup_plugins folder in /ansible-1.2/lib/ansible/runner/lookup_plugins. There are 15 .py files. Every .py file can be called using the lookup function. eg {{lookup(‘file’,‘/home/celine/Desktop/newText’)}}. The first lookup parameter, ‘file’ should correspond to one of the 15.py files.

For my case, I should create a ods.py file in the lookup_plugins folder. {{ lookup(“ods”, “foo.ods,B22”) }}. Second parameter will have 2 inputs. I have looked through the different .py files and have found some similarities.

But i dont know how to use those and adapt to create the new ods plugin. I am not familiar with python but have started reading up on it.

Are you able to help to write the ods plugin? Would appreciate alot. Thanks.

I don’t currently have cycles to help write the plugin for you.

Someone else here might, however.

It might be MUCH easier to write a tsv (tab separated values) plugin, ods spreadsheet easily exports into that. Even csv format can get very complicated (optional diff separators, optional text delimiters, etc).

With a tsv file, will i still be able to extract certain values instead of getting out the entire file since there is no more cell concept in tsv?

What about a text file? {{lookup(‘file’,‘/home/celine/Desktop/motd’)}} This looks up everything in file, motd. Can I specify which element in the file i wish to pick out? For instance the word in row 10, column 9 for example.

Thanks.