An even more elegant solution would be to use '[-3:]' to get the last three 
items regardless of how many there are.

---
- 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()[-3:] }}"



% ansible-playbook -i localhost, split.yml

PLAY [test splitting text] 
*********************************************************************************************

TASK [get the load average text] 
***************************************************************************************
ok: [localhost] => {
    "msg": [
        "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

-- 
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/F928F5C5-E013-4092-A47B-FCC5480E82C3%40nist.gov.

Reply via email to