Re: [ansible-project] rescue block does not print message despite being invoked
On Thu, 12 Mar 2020 19:12:56 -0700 (PDT) Shifa Shaikh wrote: > - name: Print custom conditional debug message > fail: > msg: >- > {{ > command_result.rc == 0 | > ternary( > "This IP is already On-Boarded.", > "The Database is not reachable." > ) > }} > > Considering command_result.rc = 0; I was expecting "This IP is already > On-Boarded." to be printed however it does not. Can you please tell me why. > [...] > TASK [Print custom conditional debug message] > ** > [1;30mtask path: /tmp/filegaurd.yml:28[0m > [0;31mfatal: [localhost]: FAILED! => {[0m > [0;31m"changed": false, [0m > [0;31m"msg": "False "[0m > [0;31m}[0m Close the comparison into the parenthesis (command_result.rc == 0) | The filter "|" has higher precedence compared to the comparison "==". Without the parenthesis the filter is evaluated first and ternary returns "The Database is not reachable.". This string is compared to command_result.rc and the result is "msg": "False" HTH, -vlado -- 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/20200313090507.5d2c5fbb%40gmail.com. pgpNASrOh2M8p.pgp Description: OpenPGP digital signature
Re: [ansible-project] rescue block does not print message despite being invoked
On Fri, 13 Mar 2020 at 04:19, Shifa Shaikh wrote: Missing parentheses where? > Right above the answer > -- Sent from a mobile device - please excuse the brevity, spelling and punctuation. -- 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/CAL8fbwMaxW4Koa6RWAp1avA9Vqrfhtr9fLXWw2FsM9Y96f%2BvFA%40mail.gmail.com.
Re: [ansible-project] rescue block does not print message despite being invoked
Missing parentheses where? My code is very similar to a working sample here: fail: msg: >- {{ command_result.stdout is search('775') | ternary( "This REQ is already Deployed. , "Database is not reachable." ) }} On Fri, 13 Mar, 2020, 8:06 am James Cassell, wrote: > > On Thu, Mar 12, 2020, at 10:12 PM, Shifa Shaikh wrote: > > Hi, > > > > I have a playbook with a task that greps for a string in a file. If the > > string is found the block should fail which is the case. However, in > > the fail module it fails to print the message. > > > > Here is my playbook: > > > > Here is my playbook: > > > > ` > > --- > > - name: "Play 1" > > hosts: localhost > > tasks: > > - block: > > - name: "Search for IP" > > command: "grep -w {{ source_host }} {{ playbook_dir }}/allhost.hosts" > > register: command_result > > failed_when: command_result.rc == 0 and action == "onboard" > > > > > > rescue: > > - name: Print custom conditional debug message > > fail: > > msg: >- > > {{ > > command_result.rc == 0 | > > You're missing parenthesis around the condition. > > V/r, > James Cassell > > > ternary( > > "This IP is already On-Boarded.", > > "The Database is not reachable." > > ) > > }} > > > > ` > > > > > > Considering command_result.rc = 0; I was expecting "This IP is already > > On-Boarded." to be printed however it does not. Can you please tell me > > why. > > > > Output: > > > > ` > > TASK [Search for IP] * > > [1;30mtask path: /tmp/filegaurd.yml:20[0m > > [0;34mUsing module file > > /usr/lib/python2.7/site-packages/ansible/modules/commands/command.py[0m > > [0;34mPipelining is enabled.[0m > > [0;34m<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: user1[0m > > [0;34m<127.0.0.1> EXEC /bin/sh -c '/usr/bin/python2 && sleep 0'[0m > > [0;31mfatal: [localhost]: FAILED! => {[0m > > [0;31m "changed": true, [0m > > [0;31m "cmd": [[0m > > [0;31m "grep", [0m > > [0;31m "-w", [0m > > [0;31m "10.9.9.91", [0m > > [0;31m "/tmp/allhost.hosts"[0m > > [0;31m ], [0m > > [0;31m "delta": "0:00:00.096103", [0m > > [0;31m "end": "2020-03-13 07:25:43.705938", [0m > > [0;31m "failed_when_result": true, [0m > > [0;31m "invocation": {[0m > > [0;31m "module_args": {[0m > > [0;31m "_raw_params": "grep -w 10.9.9.91 /tmp/allhost.hosts", [0m > > [0;31m "_uses_shell": false, [0m > > [0;31m "argv": null, [0m > > [0;31m "chdir": null, [0m > > [0;31m "creates": null, [0m > > [0;31m "executable": null, [0m > > [0;31m "removes": null, [0m > > [0;31m "stdin": null, [0m > > [0;31m "stdin_add_newline": true, [0m > > [0;31m "strip_empty_ends": true, [0m > > [0;31m "warn": true[0m > > [0;31m }[0m > > [0;31m }, [0m > > [0;31m "rc": 0, [0m > > [0;31m "start": "2020-03-13 07:25:43.609835", [0m > > [0;31m "stderr": "", [0m > > [0;31m "stderr_lines": [], [0m > > [0;31m "stdout": "10.9.9.91 USERID=user1 > > > files_list=/tmp/winstone4603745991442278706.jar,/tmp/winstone5835113081224811756.jar", > [0m > > [0;31m "stdout_lines": [[0m > > [0;31m "10.9.9.91 USERID=user1 > > > files_list=/tmp/winstone4603745991442278706.jar,/tmp/winstone5835113081224811756.jar"[0m > > [0;31m ][0m > > [0;31m}[0m > > > > > > TASK [Print custom conditional debug message] > ** > > [1;30mtask path: /tmp/filegaurd.yml:28[0m > > [0;31mfatal: [localhost]: FAILED! => {[0m > > [0;31m "changed": false, [0m > > [0;31m "msg": "False "[0m > > [0;31m}[0m > > > > > > PLAY RECAP > > * > > [0;31mlocalhost[0m : [0;32mok=1 [0m changed=0 unreachable=0 > > [0;31mfailed=1 [0m skipped=0 [0;32mrescued=1 [0m ignored=0 > > ` > > > > -- > 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/53303de2-c158-4f30-b968-44d4b9be9d36%40www.fastmail.com > . > -- 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/CAJtox0mm%2B0ei8p5uLsts4O9Nw1kj%2BAgUPxYFUap_eAnsNcnCdA%40mail.gmail.com.
Re: [ansible-project] rescue block does not print message despite being invoked
On Thu, Mar 12, 2020, at 10:12 PM, Shifa Shaikh wrote: > Hi, > > I have a playbook with a task that greps for a string in a file. If the > string is found the block should fail which is the case. However, in > the fail module it fails to print the message. > > Here is my playbook: > > Here is my playbook: > > ` > --- > - name: "Play 1" > hosts: localhost > tasks: > - block: > - name: "Search for IP" > command: "grep -w {{ source_host }} {{ playbook_dir }}/allhost.hosts" > register: command_result > failed_when: command_result.rc == 0 and action == "onboard" > > > rescue: > - name: Print custom conditional debug message > fail: > msg: >- > {{ > command_result.rc == 0 | You're missing parenthesis around the condition. V/r, James Cassell > ternary( > "This IP is already On-Boarded.", > "The Database is not reachable." > ) > }} > > ` > > > Considering command_result.rc = 0; I was expecting "This IP is already > On-Boarded." to be printed however it does not. Can you please tell me > why. > > Output: > > ` > TASK [Search for IP] * > [1;30mtask path: /tmp/filegaurd.yml:20[0m > [0;34mUsing module file > /usr/lib/python2.7/site-packages/ansible/modules/commands/command.py[0m > [0;34mPipelining is enabled.[0m > [0;34m<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: user1[0m > [0;34m<127.0.0.1> EXEC /bin/sh -c '/usr/bin/python2 && sleep 0'[0m > [0;31mfatal: [localhost]: FAILED! => {[0m > [0;31m "changed": true, [0m > [0;31m "cmd": [[0m > [0;31m "grep", [0m > [0;31m "-w", [0m > [0;31m "10.9.9.91", [0m > [0;31m "/tmp/allhost.hosts"[0m > [0;31m ], [0m > [0;31m "delta": "0:00:00.096103", [0m > [0;31m "end": "2020-03-13 07:25:43.705938", [0m > [0;31m "failed_when_result": true, [0m > [0;31m "invocation": {[0m > [0;31m "module_args": {[0m > [0;31m "_raw_params": "grep -w 10.9.9.91 /tmp/allhost.hosts", [0m > [0;31m "_uses_shell": false, [0m > [0;31m "argv": null, [0m > [0;31m "chdir": null, [0m > [0;31m "creates": null, [0m > [0;31m "executable": null, [0m > [0;31m "removes": null, [0m > [0;31m "stdin": null, [0m > [0;31m "stdin_add_newline": true, [0m > [0;31m "strip_empty_ends": true, [0m > [0;31m "warn": true[0m > [0;31m }[0m > [0;31m }, [0m > [0;31m "rc": 0, [0m > [0;31m "start": "2020-03-13 07:25:43.609835", [0m > [0;31m "stderr": "", [0m > [0;31m "stderr_lines": [], [0m > [0;31m "stdout": "10.9.9.91 USERID=user1 > files_list=/tmp/winstone4603745991442278706.jar,/tmp/winstone5835113081224811756.jar", > [0m > [0;31m "stdout_lines": [[0m > [0;31m "10.9.9.91 USERID=user1 > files_list=/tmp/winstone4603745991442278706.jar,/tmp/winstone5835113081224811756.jar"[0m > [0;31m ][0m > [0;31m}[0m > > > TASK [Print custom conditional debug message] > ** > [1;30mtask path: /tmp/filegaurd.yml:28[0m > [0;31mfatal: [localhost]: FAILED! => {[0m > [0;31m "changed": false, [0m > [0;31m "msg": "False "[0m > [0;31m}[0m > > > PLAY RECAP > * > [0;31mlocalhost[0m : [0;32mok=1 [0m changed=0 unreachable=0 > [0;31mfailed=1 [0m skipped=0 [0;32mrescued=1 [0m ignored=0 > ` > -- 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/53303de2-c158-4f30-b968-44d4b9be9d36%40www.fastmail.com.
[ansible-project] rescue block does not print message despite being invoked
Hi, I have a playbook with a task that greps for a string in a file. If the string is found the block should fail which is the case. However, in the fail module it fails to print the message. Here is my playbook: Here is my playbook: --- - name: "Play 1" hosts: localhost tasks: - block: - name: "Search for IP" command: "grep -w {{ source_host }} {{ playbook_dir }}/allhost.hosts" register: command_result failed_when: command_result.rc == 0 and action == "onboard" rescue: - name: Print custom conditional debug message fail: msg: >- {{ command_result.rc == 0 | ternary( "This IP is already On-Boarded.", "The Database is not reachable." ) }} Considering command_result.rc = 0; I was expecting "This IP is already On-Boarded." to be printed however it does not. Can you please tell me why. Output: TASK [Search for IP] * [1;30mtask path: /tmp/filegaurd.yml:20[0m [0;34mUsing module file /usr/lib/python2.7/site-packages/ansible/modules/ commands/command.py[0m [0;34mPipelining is enabled.[0m [0;34m<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: user1[0m [0;34m<127.0.0.1> EXEC /bin/sh -c '/usr/bin/python2 && sleep 0'[0m [0;31mfatal: [localhost]: FAILED! => {[0m [0;31m"changed": true, [0m [0;31m"cmd": [[0m [0;31m"grep", [0m [0;31m"-w", [0m [0;31m"10.9.9.91", [0m [0;31m"/tmp/allhost.hosts"[0m [0;31m], [0m [0;31m"delta": "0:00:00.096103", [0m [0;31m"end": "2020-03-13 07:25:43.705938", [0m [0;31m"failed_when_result": true, [0m [0;31m"invocation": {[0m [0;31m"module_args": {[0m [0;31m"_raw_params": "grep -w 10.9.9.91 /tmp/allhost.hosts", [0m [0;31m"_uses_shell": false, [0m [0;31m"argv": null, [0m [0;31m"chdir": null, [0m [0;31m"creates": null, [0m [0;31m"executable": null, [0m [0;31m"removes": null, [0m [0;31m"stdin": null, [0m [0;31m"stdin_add_newline": true, [0m [0;31m"strip_empty_ends": true, [0m [0;31m"warn": true[0m [0;31m}[0m [0;31m}, [0m [0;31m"rc": 0, [0m [0;31m"start": "2020-03-13 07:25:43.609835", [0m [0;31m"stderr": "", [0m [0;31m"stderr_lines": [], [0m [0;31m"stdout": "10.9.9.91 USERID=user1 files_list=/tmp/winstone4603745991442278706.jar,/tmp/winstone5835113081224811756.jar" , [0m [0;31m"stdout_lines": [[0m [0;31m"10.9.9.91 USERID=user1 files_list=/tmp/winstone4603745991442278706.jar,/tmp/winstone5835113081224811756.jar" [0m [0;31m][0m [0;31m}[0m TASK [Print custom conditional debug message] ** [1;30mtask path: /tmp/filegaurd.yml:28[0m [0;31mfatal: [localhost]: FAILED! => {[0m [0;31m"changed": false, [0m [0;31m"msg": "False "[0m [0;31m}[0m PLAY RECAP * [0;31mlocalhost[0m : [0;32mok=1 [0m changed=0 unreachable=0[0;31mfailed=1 [0m skipped=0[0;32mrescued=1 [0m ignored=0 -- 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/7fe0646e-8f35-4d7f-be5b-10aa6e85a56c%40googlegroups.com.