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
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]<mailto:[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://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>.
--
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.