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.
- 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
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/2b726fc8-85da-4b86-b851-55b4ebec0f40n%40googlegroups.com.
- 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
here output is not always constant
sometimes
"grepout.stdout": " /usr/bin/../share/java/kafka/*\n' '{print $2}' | awk -F'"
and sometimes
"grepout.stdout": '{print $2}' | awk -F'" \n' " /usr/bin/../share/java/kafka/*"