I am trying to find whether a certain letter exists in an stdout_lines array.
I want the role to run if there is a 'P' found in the stdout_output.
The stdout_lines array looks like this "stdout": "P\r\nA\r\nS\r\nI\r\n", "stdout_lines": ["P", "A", "S", "I"]
myrole.yml
---
- hosts: windows
gather_facts: false
roles:
- all_servers
- {role: production_server, when: prod_fact.find('P')}
The error I am getting is fatal: [hostname]: FAILED! => {"failed": true, "msg": "ERROR! The conditional check '{{prod_fact}}.find('P')' failed. The error was: ERROR! template error while templating string: expected token ',', got 'string'"}
In order to get the stdout_variable I am using set_fact
---
- name: Check Env Type and Save it in Var=prod_fact
script: files/CheckEnvType.ps1 -hostname {{inventory_hostname}}
register: result
- set_fact:
prod_fact: "{{result.stdout_lines | default('')}}"