I would like to fetch first few character from a registered variable. Can somebody please suggest me how to do that.
- hosts: node1
gather_facts: False
tasks:
- name: Check Value mango
shell: cat /home/vagrant/mango
register: result
- name: Display Result In Loop
debug: msg="Version is {{ result.stdout[5] }}"
The above code displays the fifth character rather first 5 characters of the registered string.
PLAY [node1] ******************************************************************
TASK: [Check Value mango] *****************************************************
changed: [10.200.19.21] => {"changed": true, "cmd": "cat /home/vagrant/mango", "delta": "0:00:00.003000", "end": "2015-08-19 09:29:58.229244", "rc": 0, "start": "2015-08-19 09:29:58.226244", "stderr": "", "stdout": "d3aa6131ec1a2e73f69ee150816265b5617d7e69", "warnings": []}
TASK: [Display Result In Loop] ************************************************
ok: [10.200.19.21] => {
"msg": "Version is 1"
}
PLAY RECAP ********************************************************************
10.200.19.21 : ok=2 changed=1 unreachable=0 failed=0
You can work with ranges:
- name: Display Result In Loop
debug: msg="Version is {{ result.stdout[:5] }}"
This will print the first 5 characters.
1:5
would print the characters 2 to 5, skipping the 1st char.5:
Would skip the the first 5 chars and print the rest of the stringIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With