1

I have ansible role which checks the latest backups from my databases (cassandra and elasticsearch) so i have this output

ansible-playbook other/check_backup_status.yml -i hosts/mvd/prod/hosts.yml PLAY [check backup] *************************************************************************************************************************************************************************************************************** TASK [check_backup : check backups for cluster elasticsearch-bishkek] *************************************************************************************************************************************************************************** skipping: [elasticsearch-bishkek-02] skipping: [elasticsearch-bishkek-03] skipping: [elasticsearch-kabul1] skipping: [elasticsearch-kabul2] skipping: [elasticsearch-kabul3] skipping: [elasticsearch-kabul4] skipping: [elasticsearch-kabul5] skipping: [elasticsearch-kabul6] skipping: [cassandra-bishkek01] skipping: [cassandra-bishkek02] skipping: [cassandra-bishkek03] [WARNING]: Consider using the get_url or uri module rather than running 'curl'. If you need to use command because get_url or uri is insufficient you can add 'warn: false' to this command task or set 'command_warnings=False' in ansible.cfg to get rid of this message. changed: [elasticsearch-bishkek-01] TASK [check_backup : Show last 10 backups for elasticsearch bishkek cluster] *********************************************************************************************************************************************************** ok: [elasticsearch-bishkek-01] => { "msg": [ "snapshot-2021-01-02-14:20:01 SUCCESS 1609575601 08:20:01 1609575655 08:20:55 54.2s 106 364 0 364", "snapshot-2021-01-02-20:20:01 SUCCESS 1609597201 14:20:01 1609597260 14:21:00 58.7s 106 364 0 364", "snapshot-2021-01-03-09:20:01 SUCCESS 1609644002 03:20:02 1609644092 03:21:32 1.4m 106 364 0 364", "snapshot-2021-01-03-14:20:01 SUCCESS 1609662001 08:20:01 1609662173 08:22:53 2.8m 106 364 0 364", "snapshot-2021-01-03-20:20:01 SUCCESS 1609683602 14:20:02 1609683671 14:21:11 1.1m 106 364 0 364", "snapshot-2021-01-04-09:20:01 SUCCESS 1609730401 03:20:01 1609730467 03:21:07 1m 106 364 0 364", "snapshot-2021-01-04-14:20:01 SUCCESS 1609748402 08:20:02 1609748460 08:21:00 57.8s 106 364 0 364", "snapshot-2021-01-04-20:20:01 SUCCESS 1609770001 14:20:01 1609770064 14:21:04 1m 106 364 0 364", "snapshot-2021-01-05-09:20:01 SUCCESS 1609816801 03:20:01 1609816856 03:20:56 54.5s 106 364 0 364", "snapshot-2021-01-05-14:20:01 SUCCESS 1609834802 08:20:02 1609835018 08:23:38 3.5m 107 365 0 365" ] } skipping: [elasticsearch-bishkek-02] skipping: [elasticsearch-bishkek-03] skipping: [elasticsearch-kabul1] skipping: [elasticsearch-kabul2] skipping: [elasticsearch-kabul3] skipping: [elasticsearch-kabul4] skipping: [elasticsearch-kabul5] skipping: [elasticsearch-kabul6] skipping: [cassandra-bishkek01] skipping: [cassandra-bishkek02] skipping: [cassandra-bishkek03] TASK [check_backup : check backups for elasticsearch kabul cluster] ****************************************************************************************************************************************************************************** skipping: [elasticsearch-bishkek-01] skipping: [elasticsearch-bishkek-02] skipping: [elasticsearch-bishkek-03] skipping: [elasticsearch-kabul2] skipping: [elasticsearch-kabul3] skipping: [elasticsearch-kabul4] skipping: [elasticsearch-kabul5] skipping: [elasticsearch-kabul6] skipping: [cassandra-bishkek01] skipping: [cassandra-bishkek02] skipping: [cassandra-bishkek03] changed: [elasticsearch-kabul1] TASK [check_backup : Show last 10 backups for elasticsearch-kabul] ************************************************************************************************************************************************************************** skipping: [elasticsearch-bishkek-01] skipping: [elasticsearch-bishkek-02] skipping: [elasticsearch-bishkek-03] ok: [elasticsearch-kabul1] => { "msg": [ "snapshot-2020-12-27-06:00:01 SUCCESS 1609027201 00:00:01 1609030938 01:02:18 1h 47 131 0 131", "snapshot-2020-12-28-06:00:01 SUCCESS 1609113602 00:00:02 1609114922 00:22:02 21.9m 50 140 0 140", "snapshot-2020-12-29-06:00:01 SUCCESS 1609200002 00:00:02 1609201779 00:29:39 29.6m 52 146 0 146", "snapshot-2020-12-30-06:00:01 SUCCESS 1609286402 00:00:02 1609290726 01:12:06 1.2h 30 76 0 76", "snapshot-2020-12-31-06:00:01 SUCCESS 1609372802 00:00:02 1609375122 00:38:42 38.6m 31 79 0 79", "snapshot-2021-01-01-06:00:01 SUCCESS 1609459202 00:00:02 1609461236 00:33:56 33.8m 33 85 0 85", "snapshot-2021-01-02-06:00:01 SUCCESS 1609545602 00:00:02 1609546580 00:16:20 16.3m 36 94 0 94", "snapshot-2021-01-03-06:00:01 SUCCESS 1609632003 00:00:03 1609633134 00:18:54 18.8m 37 97 0 97", "snapshot-2021-01-04-06:00:01 SUCCESS 1609718402 00:00:02 1609719266 00:14:26 14.4m 40 106 0 106", "snapshot-2021-01-05-06:00:01 SUCCESS 1609804802 00:00:02 1609805812 00:16:52 16.8m 41 109 0 109" ] } skipping: [elasticsearch-kabul2] skipping: [elasticsearch-kabul3] skipping: [elasticsearch-kabul4] skipping: [elasticsearch-kabul5] skipping: [elasticsearch-kabul6] skipping: [cassandra-bishkek01] skipping: [cassandra-bishkek02] skipping: [cassandra-bishkek03] TASK [check_backup : check backups for Cassandra cluster] ************************************************************************************************************************************************************************* skipping: [elasticsearch-bishkek-01] skipping: [elasticsearch-bishkek-02] skipping: [elasticsearch-bishkek-03] skipping: [elasticsearch-kabul1] skipping: [elasticsearch-kabul2] skipping: [elasticsearch-kabul3] skipping: [elasticsearch-kabul4] skipping: [elasticsearch-kabul5] skipping: [elasticsearch-kabul6] skipping: [cassandra-bishkek02] skipping: [cassandra-bishkek03] changed: [cassandra-bishkek01] TASK [check_backup : show last 10 backups for Cassandra cluster] ********************************************************************************************************************************************************* skipping: [elasticsearch-bishkek-01] skipping: [elasticsearch-bishkek-02] skipping: [elasticsearch-bishkek-03] skipping: [elasticsearch-kabul1] skipping: [elasticsearch-kabul2] skipping: [elasticsearch-kabul3] skipping: [elasticsearch-kabul4] skipping: [elasticsearch-kabul5] skipping: [elasticsearch-kabul6] ok: [cassandra-bishkek01] => { "msg": [ "2021-01-03__09:20:01 (started: 2021-01-03 09:20:02, finished: 2021-01-03 09:21:16)", "2021-01-03__14:20:01 (started: 2021-01-03 14:20:02, finished: 2021-01-03 14:20:58)", "2021-01-03__20:20:01 (started: 2021-01-03 20:20:02, finished: 2021-01-03 20:21:01)", "2021-01-04__09:20:01 (started: 2021-01-04 09:20:02, finished: 2021-01-04 09:21:36)", "2021-01-04__14:20:01 (started: 2021-01-04 14:20:02, finished: 2021-01-04 14:20:59)", "2021-01-04__20:20:01 (started: 2021-01-04 20:20:02, finished: 2021-01-04 20:21:02)", "2021-01-05__09:20:01 (started: 2021-01-05 09:20:02, finished: 2021-01-05 09:21:25)", "2021-01-05__14:20:01 (started: 2021-01-05 14:20:02, finished: 2021-01-05 14:21:13)", "", "Incomplete backups found. You can run \"medusa status --backup-name <name>\" for more details" ] } skipping: [cassandra-bishkek02] skipping: [cassandra-bishkek03] PLAY RECAP ************************************************************************************************************************************************************************************************************************ elasticsearch-kabul1 : ok=2 changed=1 unreachable=0 failed=0 skipped=6 rescued=0 ignored=0 elasticsearch-kabul2 : ok=0 changed=0 unreachable=0 failed=0 skipped=8 rescued=0 ignored=0 elasticsearch-kabul3 : ok=0 changed=0 unreachable=0 failed=0 skipped=8 rescued=0 ignored=0 elasticsearch-kabul4 : ok=0 changed=0 unreachable=0 failed=0 skipped=8 rescued=0 ignored=0 elasticsearch-kabul5 : ok=0 changed=0 unreachable=0 failed=0 skipped=8 rescued=0 ignored=0 elasticsearch-kabul6 : ok=0 changed=0 unreachable=0 failed=0 skipped=8 rescued=0 ignored=0 elasticsearch-bishkek-01 : ok=2 changed=1 unreachable=0 failed=0 skipped=6 rescued=0 ignored=0 elasticsearch-bishkek-02 : ok=0 changed=0 unreachable=0 failed=0 skipped=8 rescued=0 ignored=0 elasticsearch-bishkek-03 : ok=0 changed=0 unreachable=0 failed=0 skipped=8 rescued=0 ignored=0 cassandra-bishkek01 : ok=2 changed=1 unreachable=0 failed=0 skipped=6 rescued=0 ignored=0 cassandra-bishkek02 : ok=0 changed=0 unreachable=0 failed=0 skipped=8 rescued=0 ignored=0 cassandra-bishkek03 : ok=0 changed=0 unreachable=0 failed=0 skipped=8 rescued=0 ignored=0 

so as you can see the output is pretty big, and i want to exclude all except the Show last 10 backups * tasks

for example i only want to see this output

TASK [check_backup : Show last 10 backups for elasticsearch bishkek cluster] *********************************************************************************************************************************************************** ok: [elasticsearch-bishkek-01] => { "msg": [ "snapshot-2021-01-02-14:20:01 SUCCESS 1609575601 08:20:01 1609575655 08:20:55 54.2s 106 364 0 364", "snapshot-2021-01-02-20:20:01 SUCCESS 1609597201 14:20:01 1609597260 14:21:00 58.7s 106 364 0 364", "snapshot-2021-01-03-09:20:01 SUCCESS 1609644002 03:20:02 1609644092 03:21:32 1.4m 106 364 0 364", "snapshot-2021-01-03-14:20:01 SUCCESS 1609662001 08:20:01 1609662173 08:22:53 2.8m 106 364 0 364", "snapshot-2021-01-03-20:20:01 SUCCESS 1609683602 14:20:02 1609683671 14:21:11 1.1m 106 364 0 364", "snapshot-2021-01-04-09:20:01 SUCCESS 1609730401 03:20:01 1609730467 03:21:07 1m 106 364 0 364", "snapshot-2021-01-04-14:20:01 SUCCESS 1609748402 08:20:02 1609748460 08:21:00 57.8s 106 364 0 364", "snapshot-2021-01-04-20:20:01 SUCCESS 1609770001 14:20:01 1609770064 14:21:04 1m 106 364 0 364", "snapshot-2021-01-05-09:20:01 SUCCESS 1609816801 03:20:01 1609816856 03:20:56 54.5s 106 364 0 364", "snapshot-2021-01-05-14:20:01 SUCCESS 1609834802 08:20:02 1609835018 08:23:38 3.5m 107 365 0 365" ] } TASK [check_backup : show last 10 backups for Cassandra cluster] ********************************************************************************************************************************************************* skipping: [elasticsearch-bishkek-01] skipping: [elasticsearch-bishkek-02] skipping: [elasticsearch-bishkek-03] skipping: [elasticsearch-kabul1] skipping: [elasticsearch-kabul2] skipping: [elasticsearch-kabul3] skipping: [elasticsearch-kabul4] skipping: [elasticsearch-kabul5] skipping: [elasticsearch-kabul6] ok: [cassandra-bishkek01] => { "msg": [ "2021-01-03__09:20:01 (started: 2021-01-03 09:20:02, finished: 2021-01-03 09:21:16)", "2021-01-03__14:20:01 (started: 2021-01-03 14:20:02, finished: 2021-01-03 14:20:58)", "2021-01-03__20:20:01 (started: 2021-01-03 20:20:02, finished: 2021-01-03 20:21:01)", "2021-01-04__09:20:01 (started: 2021-01-04 09:20:02, finished: 2021-01-04 09:21:36)", "2021-01-04__14:20:01 (started: 2021-01-04 14:20:02, finished: 2021-01-04 14:20:59)", "2021-01-04__20:20:01 (started: 2021-01-04 20:20:02, finished: 2021-01-04 20:21:02)", "2021-01-05__09:20:01 (started: 2021-01-05 09:20:02, finished: 2021-01-05 09:21:25)", "2021-01-05__14:20:01 (started: 2021-01-05 14:20:02, finished: 2021-01-05 14:21:13)", "", "Incomplete backups found. You can run \"medusa status --backup-name <name>\" for more details" ] } 

and for the Cassandra the same so how can i do this using the linux tools? thanks for the answers

1
  • Is the processing to be done retrospectively after the ansible log file has been created or as the playbook runs? Commented Jan 5, 2021 at 14:55

1 Answer 1

1

If the output of the ansible-playbook other/check_backup_status.yml -i hosts/mvd/prod/hosts.yml command goes to the standard output, I can redirect that output to awk in the next way:

ansible-playbook other/check_backup_status.yml -i hosts/mvd/prod/hosts.yml | awk '/[Ss]how last 10 backups/,/^\}/' 

Basically, with the awk command above, you print only the ranges of lines starting from a line containing Show last 10 backups (show capitalised or not) and stopping after a line containing a } as first character.

Sign up to request clarification or add additional context in comments.

3 Comments

If it is important to save a blank line between the ranges of printed lines, we will have to complexify the script.
Thank you! god bless you my friend!
@noze_potato: you are welcome. If you are happy with my answer, please accept the solution and/or upvote it by clicking on the corresponding icon.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.