Let's say that content of file "/etc/my_file.txt" is like this:
a b CC d
a c BB d
a d DD e
I am checking it and writing output to variable:
- name: Check 3rd column of file
shell: cat /etc/my_file.txt | awk '{print $3}'
register: test
Is there a way to check if the 3rd column of that file has values EXACTLY the same as given in debug section bellow ?
I've tried to converting it into a list:
- set_fact:
std_out: "{{ test.stdout.split()|list }}"
... and then comparing it with particular list items:
- name: Test if it worked
debug:
msg: Values are differrent
when: std_out[0] == "CC" and std_out[1] == "BB" and std_out[2] == "DD"
but got errors like this:
The error was: template error while templating string: unexpected char u'"'
Tried couple more things but still got some issues and feeling like banging my head against the wall :-) Any help would be apprieciated.
My setup is:
ansible 2.9.14
python version = 2.7.5
std_out: "{{ test.stdout.split()|list }}", and yourwhenclause is also missing a double quote =>when: std_out[0] == "CC" and std_out[1] == "BB" and std_out[2] == "DD"