load_avg: "{{ up_out.stdout_lines[0].split()[7:] }}"
---
- 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
--
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/31258954-4fc0-4ef7-91b1-2fb7f92b5066n%40googlegroups.com.
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
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/A3889D94-A02D-4C35-891F-693D087D8459%40nist.gov.
--
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/20230228081123.140af349%40gmail.com.