Need help in formatting register variable

11 views
Skip to first unread message

Sivaraman P

unread,
May 4, 2020, 7:40:41 AM5/4/20
to Ansible Project
I have used the below play to display the files and folders with some pattern

- name: Display backup files
shell: "du -h {{partition}} --time | sort -rh | grep -o -P '(.*bk|.*bkup|.*bak|.*backup|.*logs' | sort -rh | awk -F'\t' '{print $3}'|uniq|head -n 100"
register: status


and while using this command i am getting output as below which i have stored in register variable called status

7.4G 2018-12-24 03:46 /logs/backups
6.4G 2018-12-24 03:46 /logs/backups/config_bkp_11dec
7.4G 2018-12-24 03:46 /logs/backups/config_bkp_18nov

The thing is i need to eliminate the entire child path lines amd need to hold the parent path /logs/backups... is there anyway to do that...


Dick Visser

unread,
May 4, 2020, 12:12:41 PM5/4/20
to ansible...@googlegroups.com
Hi

Not sure what "eliminate the entire child path lines" means - is that
some local jargon?
Giving actual preferred output would avoid us doing any guestimations
and/or (mis)interpretations of said jargon.

Either way, yes you're using ansible, but just it's 'shell' module as
a conveyor mechanism to execute a lot of piped shell commands.
I would suggest adding a few extra.
If any, this would avoid you dividing the text processing between the
shell and ansible.

Dick
> --
> 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 ansible-proje...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/68e389ef-1d44-48d4-8164-9ee8371bfafa%40googlegroups.com.



--
Dick Visser
Trust & Identity Service Operations Manager
GÉANT

Stefan Hornburg (Racke)

unread,
May 4, 2020, 1:30:08 PM5/4/20
to ansible...@googlegroups.com
On 5/4/20 6:12 PM, Dick Visser wrote:
> Hi
>
> Not sure what "eliminate the entire child path lines" means - is that
> some local jargon?
> Giving actual preferred output would avoid us doing any guestimations
> and/or (mis)interpretations of said jargon.
>
> Either way, yes you're using ansible, but just it's 'shell' module as
> a conveyor mechanism to execute a lot of piped shell commands.
> I would suggest adding a few extra.
> If any, this would avoid you dividing the text processing between the
> shell and ansible.
>
> Dick

I agree, this is not related to Ansible proper. And I'm also sure that this shell command is way too complicated.

Regards
Racke

>
>
>
> On Mon, 4 May 2020 at 13:40, Sivaraman P <shivar...@gmail.com> wrote:
>>
>> I have used the below play to display the files and folders with some pattern
>>
>> - name: Display backup files
>> shell: "du -h {{partition}} --time | sort -rh | grep -o -P '(.*bk|.*bkup|.*bak|.*backup|.*logs' | sort -rh | awk -F'\t' '{print $3}'|uniq|head -n 100"
>> register: status
>>
>>
>> and while using this command i am getting output as below which i have stored in register variable called status
>>
>> 7.4G 2018-12-24 03:46 /logs/backups
>> 6.4G 2018-12-24 03:46 /logs/backups/config_bkp_11dec
>> 7.4G 2018-12-24 03:46 /logs/backups/config_bkp_18nov
>>
>> The thing is i need to eliminate the entire child path lines amd need to hold the parent path /logs/backups... is there anyway to do that...
>>
>>
>> --
>> 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 ansible-proje...@googlegroups.com.
>> To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/68e389ef-1d44-48d4-8164-9ee8371bfafa%40googlegroups.com.
>
>
>


--
Ecommerce and Linux consulting + Perl and web application programming.
Debian and Sympa administration. Provisioning with Ansible.

signature.asc
Reply all
Reply to author
Forward
0 new messages