Using ansible data management. I have use case to solve.

15 views
Skip to first unread message

GURU W

unread,
Mar 23, 2018, 2:10:04 AM3/23/18
to Ansible Project
Hi All,

I know ansible is for configuration management, provisioning, task automation. Ansible is already use to solve the purpose.


Background: I have shell scripts to read a filename from source and copying them to declared target location.

Ex:  "xyz_date_123.txt" (script does the task of reading the date in the filename and creates target directory aswel, later places  the file inside destination say: Project/YYYY/MM/DD directory)


I was wondering if we could do this using ansible, I have "functions", "if", "else" statements. Wasn't sure if we could use ansible to solve this purpose.

Expert advice would be most appreciated.

Kai Stian Olstad

unread,
Mar 23, 2018, 7:26:54 AM3/23/18
to ansible...@googlegroups.com
On 23.03.2018 07:10, GURU W wrote:
> Hi All,
>
> I know ansible is for configuration management, provisioning, task
> automation. Ansible is already use to solve the purpose.
>
>
> *Background:* I have shell scripts to read a filename from source and
> copying them to declared target location.
>
> *Ex:* "xyz_date_123.txt" (script does the task of reading the date in
> the
> filename and creates target directory aswel, later places the file
> inside
> destination say: Project/YYYY/MM/DD directory)
>
>
> I was wondering if we could do this using ansible, I have "functions",
> "if", "else" statements. Wasn't sure if we could use ansible to solve
> this
> purpose.
>
> Expert advice would be most appreciated.

It's doable.

find module to find the file, .split [1] on the filename to get the date
out and then some slicing of the result to get the year, month and day.
Then it's just using fetch and/or copy module depending where the file
should be copied to.


[1] https://docs.python.org/2/library/stdtypes.html#str.split


--
Kai Stian Olstad
Reply all
Reply to author
Forward
0 new messages