Thanks a lot for the valuable input.. On Monday, February 27, 2023 at 11:30:52 PM UTC+5:30 Hearn, Stan J. wrote:
> Veera, > > > > Be careful splitting uptime on white space because when a system is up > less than 24 hours, it will show > > > > 12:58:10 up 6:51, 0 users, load average: 1.08, 0.99, 1.05 > > > > which will have one less white space and your desired output will be > position 6. > > > > I would recommend splitting the output on comma. The fourth value will > always be load average. > > > > Regards, > > Stan > > > > *From:* 'Rowe, Walter P. (Fed)' via Ansible Project < > [email protected]> > *Sent:* Monday, February 27, 2023 12:28 PM > *To:* [email protected] > *Subject:* [EXTERNAL] Re: [ansible-project] split with multiple columns > in debug > > > > load_avg: "{{ up_out.stdout_lines[0].split()[7:] }}" > > > > Just use [7:] to get from position 7 on in your list. > > > > > > --- > > - name: test splitting text > > hosts: localhost > > become: false > > gather_facts: false > > vars: > > text_to_split: "18:37:01 up 5 days, 4:37, 2 users, load average: > 0.02, 0.05, 0.00" > > tasks: > > - name: get the load average text > > debug: > > msg: "{{ text_to_split.split()[7:] }}" > > > > > > > > > > > > > > *% ansible-playbook -i localhost, split.yml* > > > > PLAY [test splitting text] > ********************************************************************************************* > > > > TASK [get the load average text] > *************************************************************************************** > > ok: [localhost] => { > > "msg": [ > > "load", > > "average:", > > "0.02,", > > "0.05,", > > "0.00" > > ] > > } > > > > PLAY RECAP > ************************************************************************************************************* > > localhost : ok=1 changed=0 unreachable=0 > failed=0 skipped=0 rescued=0 ignored=0 > > > > > Walter > -- > Walter Rowe, Division Chief > Infrastructure Services, OISM > Mobile: 202.355.4123 <(202)%20355-4123> > > > > On Feb 27, 2023, at 11:46 AM, Veera <[email protected]> wrote: > > > > Hi, > > > > When I try to split the output of uptime to capture the "load average from > the below line > > > > $ uptime > 18:37:01 up 5 days, 4:37, 2 users, load average: 0.02, 0.05, 0.00 > > > > using the below playbook > > > > --- > - name: uptime_collect22 > hosts: localhost > gather_facts: no > tasks: > - name: register the uptime > shell: "uptime" > register: up_out > > - set_fact: > #load_avg: "{{ up_out.stdout_lines[0].split()[[7],[8],[9],[10]] }}" > load_avg: "{{ up_out.stdout_lines[0].split()[7] }}" > > - name: print the load average > debug: > var: load_avg > > > > when i execute i got the output debug as > > TASK [print the load average ] > *********************************************************************************************************************************************** > ok: [my-client-2] => { > "load_avg": "load" > } > > > > I can split the stdout lines . How can I split/print with multiple > columns similar to awk '{print $7,$8,$9,$10}' .? > > Expected output: "load average: 0.02, 0.05, 0.00" > > > > I can achieve it with shell module with uptime |awk '{print $8,$9,$10, > $11, $12}' > > However I want to check the ansible filtering and split > > > > > > > > -- > 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/31258954-4fc0-4ef7-91b1-2fb7f92b5066n%40googlegroups.com > > <https://urldefense.com/v3/__https:/gcc02.safelinks.protection.outlook.com/?url=https*3A*2F*2Fgroups.google.com*2Fd*2Fmsgid*2Fansible-project*2F31258954-4fc0-4ef7-91b1-2fb7f92b5066n*2540googlegroups.com*3Futm_medium*3Demail*26utm_source*3Dfooter&data=05*7C01*7Cwalter.rowe*40nist.gov*7C54ba8576ec0b40e63dfd08db18e23fba*7C2ab5d82fd8fa4797a93e054655c61dec*7C1*7C0*7C638131132250539784*7CUnknown*7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0*3D*7C3000*7C*7C*7C&sdata=OTm3zMPEJmid3Y*2B38zRQiCYoN*2FOuSzGjEN*2B2p94yT3U*3D&reserved=0__;JSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJQ!!Fto3Xw!ustaILJ31tnDLrQ49tlAS1IVT343dBG4LnrxDkuQ4fv0P1glM5u_2lyoFFfQ3dzZocd7wHgKMKIdGaX4XW-eZX2dTfmV4Rw$> > . > > > > -- > 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/A3889D94-A02D-4C35-891F-693D087D8459%40nist.gov > > <https://urldefense.com/v3/__https:/groups.google.com/d/msgid/ansible-project/A3889D94-A02D-4C35-891F-693D087D8459*40nist.gov?utm_medium=email&utm_source=footer__;JQ!!Fto3Xw!ustaILJ31tnDLrQ49tlAS1IVT343dBG4LnrxDkuQ4fv0P1glM5u_2lyoFFfQ3dzZocd7wHgKMKIdGaX4XW-eZX2dZ6rsgAg$> > . > -- 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/0d49e1a5-3148-4bda-a4e0-fc341f684229n%40googlegroups.com.
