i did try that as well but no luck as i have already mentioned in my 
previous conversation.

below is the complete code, output i want is 7.2.5 from jar line. thats it. 
But i m missing something may taking long route when simple solution is 
there

  - name: take command grep output

    shell: 

      cmd: "ps -ef | grep -i kafka | grep -i server.prop | awk -F'-cp' 
'{print $2}' | awk -F':' '{print $1}'"

    register: grepout

    tags: verchk1

  


  - name: setfact and pring 

    set_fact:

      pathd: "{{ (grepout.stdout.split('\n')[0] | replace('bin/../', '') | 
replace('*','') | replace(' /','/')) }}" 

#       pathd: "{% if  'kafka' in (grepout.stdout.split('\n')[0] | 
replace('bin/../', '') | replace('*','') | replace(' /','/')) 
%}'hi'{%else}'bye'{% endif %}}" 

#      - pathd1: "{% if 'kafka' in pathd %}pathd{% else %}''{% endif %}"

  

  - name: setfact for 2nd var

    set_fact:

      pathd1: "{% if 'kafka' in pathd %}{{pathd}}{% else %}''{% endif %}" 


  - name: pathd ls

    find:

      paths: "{{pathd1}}"

      patterns: "kafka_*ccs.jar"

#      use_regex: true

    register: vername


  - name : get the complete path

    set_fact:

#      files_found_path: "{{ vername.files.path[1] }}"

      files_found_path: "{{ vername.files | map(attribute='path') | list }}"


  - name: debug grepout

    debug:

#      msg: "this is the version {{ vername.files.path }}"

      var: files_found_path

    tags: vern


#  - name: get version

#    set_fact:

#      versionn: "{{ files_found_path.split('-')[1] }}"


#  - name: debug grepout

#    debug:

#      msg: "this is the version {{ vername.files.path }}"

#      var: versionn

#    tags: vern



On Tuesday, May 23, 2023 at 7:27:19 PM UTC+5:30 Abhijeet Kasurde wrote:

> files_found_path is an array/list. So you need files_found_path[0].split
>
> On Tue, May 23, 2023 at 5:42 AM Sameer Modak <sameer.m...@gmail.com> 
> wrote:
>
>> Hello Team,
>>
>> Code
>>
>> name: debug grepout
>>
>>     debug:
>>
>> #      msg: "this is the version {{ vername.files.path }}"
>>
>>       var: *files_found_path*
>>
>>     tags: vern
>>
>> Output:
>>
>> files_found_path": [
>>
>>         "/opt/confluent-7.2.5/kafka/share/java/kafka/kafka_2.13-*7.2.5*
>> -ccs.jar"
>>
>>     ]
>>
>>
>>  Above code is working but after that it failing with below code, i need 
>> *7.2.5* before -css in above output but failing to get that tried 
>> *files_found_path[0].split(‘-‘) 
>> as well*
>>
>>  - name: get version
>>
>>     set_fact:
>>
>>       versionn: "{{ *files_found_path.split(‘-‘)[0] *}}"
>>
>> TASK [get version] 
>> ***************************************************************************************************************************************************************************
>>
>> fatal: [host1: FAILED! => {"msg": "The task includes an option with an 
>> undefined variable. The error was: 'list object' has no attribute 'split'. 
>> 'list object' has no attribute 'split'\n\nThe error appears to be in 
>> '/Users/sameer_modak/ansibledemo/testing.yml': line 54, column 5, but 
>> may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe 
>> offending line appears to be:\n\n\n  - name: get version\n    ^ here\n"}
>>
>> fatal: [host2]: FAILED! => {"msg": "The task includes an option with an 
>> undefined variable. The error was: 'list object' has no attribute 'split'. 
>> 'list object' has no attribute 'split'\n\nThe error appears to be in 
>> '/Users/sameer_modak/ansibledemo/testing.yml': line 54, column 5, but 
>> may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe 
>> offending line appears to be:\n\n\n  - name: get version\n    ^ here\n"}
>>
>> fatal: [host3]: FAILED! => {"msg": "The task includes an option with an 
>> undefined variable. The error was: 'list object' has no attribute 'split'. 
>> 'list object' has no a
>>
>>
>>
>> Thanks in advance.
>>
>> -- 
>> 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/9e09186d-7715-49d7-ad37-b8f41feebac7n%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/ansible-project/9e09186d-7715-49d7-ad37-b8f41feebac7n%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>
>
> -- 
> Thanks,
> Abhijeet Kasurde
>

-- 
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-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/2b726fc8-85da-4b86-b851-55b4ebec0f40n%40googlegroups.com.

Reply via email to