On 2/16/21 9:42 AM, Vikram S wrote:
> Hi,
>
> Thanks for your assistance. Please find output for both the playbooks as you requrested:
So if you have "hostname router28" in output.stdout, you can use the following when condition:
when: output.stdout is search('router28$')
This condition is true when the string "router28" is at the end of output.stdout.
Regards
Racke
>
> *OUTPUT FOR 1ST PLAYBOOK (WORKING ONE):*
> TASK [debug]
> ***************************************************************************************************************************
> ok: [R1] => {
> "output": {
> "ansible_facts": {
> "discovered_interpreter_python": "/usr/bin/python"
> },
> "changed": false,
> "deprecations": [
> {
> "msg": "Distribution Ubuntu 18.04 on host R1 should use /usr/bin/python3, but is using /usr/bin/python
> for backward compatibility with prior Ansible releases. A future Ansible release will default to using the discovered
> platform python for this host. See
https://docs.ansible.com/ansible/2.9/reference_appendices/interpreter_discovery.html
> for more information",
> "version": "2.12"
> }
> ],
> *"failed": false,*
> * "stdout": [*
> * "hostname router28"*
> * ],*
> * "stdout_lines": [*
> * [*
> * "hostname router28"*
> --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
> *OUTPUT FOR 2ND PLAYBOOK (NON-WORKING ONE):*
>
> PLAY [show hostname]
> *******************************************************************************************************************
>
> TASK [configure hostname]
> **************************************************************************************************************
> [DEPRECATION WARNING]: Distribution Ubuntu 18.04 on host R1 should use /usr/bin/python3, but is using /usr/bin/python
> for backward
> compatibility with prior Ansible releases. A future Ansible release will default to using the discovered platform python
> for this host.
> See
https://docs.ansible.com/ansible/2.9/reference_appendices/interpreter_discovery.html for more information. This
> feature will be
> removed in version 2.12. Deprecation warnings can be disabled by setting deprecation_warnings=False in ansible.cfg.
> changed: [R1]
>
> *TASK [debug]
> ****************************************************************************************************************************
> *fatal: [R1]: FAILED! => {"msg": "The conditional check ''router11' in output.stdout[0]' failed. The error was: error
> while evaluating conditional ('router11' in output.stdout[0]): Unable to look up a name or access an attribute in
> template string ({% if 'router11' in output.stdout[0] %} True {% else %} False {% endif %}).\nMake sure your variable
> name does not contain invalid characters like '-': argument of type 'AnsibleUndefined' is not iterable\n\nThe error
> appears to be in '/root/sample8.yaml': line 15, column 7, but may\nbe elsewhere in the file depending on the exact
> syntax problem.\n\nThe offending line appears to be:\n\n\n - debug:\n ^ here\n"}*
> <
https://groups.google.com/d/msgid/ansible-project/8bb51686-7f9a-4c88-8148-b94063103649n%40googlegroups.com?utm_medium=email&utm_source=footer
>
https://groups.google.com/d/msgid/ansible-project/4bc08ea4-622a-4f27-b2cd-f92c588a5030n%40googlegroups.com
> <
https://groups.google.com/d/msgid/ansible-project/4bc08ea4-622a-4f27-b2cd-f92c588a5030n%40googlegroups.com?utm_medium=email&utm_source=footer>.