What happens when you run the command manually the first time round? What is the exit code and what is the output, as it says a templating type error occurred I would check these things first. It may be the command when first run does not output what you expect it to.
Kind Regards On Sunday, 20 November 2016 19:06:46 UTC, [email protected] wrote: > > Hello - Assistance requested. > > I believe I've coded a nasty bug into my ansible playbook and I'm not sure > how to unravel it. In my observations, the code throws an "Unexpected > templating type error occurred" whenever I *first *run a task. All > subsequent runs do not throw the error again, even if I backout the changes > to redo them. Some code snippets below. > > role1/tasks/main.yml: > - name: database param_def select > tags: db > include: roles/role_utility_sqlplus/tasks/main.yml > vars: > query_type: "select" > table: "param_def" > filename: "dbselect_paramdef_mhe.sql" > db_logname: "{{ WMS_Schema }}_{{ WMS_Servicename > }}_db_paramdef_mhe_{{ lookup('pipe', 'date +%Y-%m-%d_%H%M%S') }}.log" > db_absolute_logpath: "/dev/null" > > - name: set_fact database select output > tags: db > set_fact: > db_select_output: "{{ expect_output }}" > > - name: database param_def insert > tags: db > include: roles/role_utility_sqlplus/tasks/main.yml > vars: > query_type: "insert" > table: "param_def" > filename: "dbinsert_paramdef_mhe.sql" > db_logname: "{{ WMS_Schema }}_{{ WMS_Servicename > }}_db_paramdef_mhe_{{ lookup('pipe', 'date +%Y-%m-%d_%H%M%S') }}.log" > db_absolute_logpath: "{{ log_dir }}/{{ db_logname }}" > when: db_select_output.stdout | search("no rows selected") > > roles/role_utility_sqlplus/tasks/main.yml: > - name: Database - Stage {{ table }} {{ query_type }} sql from template > tags: db > template: > src={{ filename }}.j2 > dest="{{ staged_config_dir }}/{{ inventory_hostname_short }}/{{ > filename }}" > backup=yes > changed_when: false > > > - name: Database - Execute {{ table }} {{ query_type }} > tags: db > expect: > command: "/bin/bash" > responses: > \$ $: > - . ~/.profile > - "sqlplus {{ WMS_Schema }}/$PASSWORD@{{ WMS_Servicename }}" > - exit > SQL> $: > - set echo on > - spool {{ db_absolute_logpath }} > - "@{{ staged_config_dir }}/{{ inventory_hostname_short }}/{{ > filename }}" > - spool off > - quit > timeout: 5 > echo: yes > register: expect_output > changed_when: query_type != "select" > failed_when: expect_output.stdout | search("(ORA|SP2)-[0-9]+") > > Occasional 'first time' error: > >> TASK [role_config_mhe : Database - Execute param_def include] >> ******************* >> fatal: [ptl01a0fap006]: FAILED! => {"failed": true, "msg": "The >> conditional check 'expect_output.stdout | search(\"(ORA|SP2)-[0-9]+\")' >> failed. The error was: Unexpected templating type error occurred on ({% >> if expect_output.stdout | search(\"(ORA|SP2)-[0-9]+\") %} True {% else >> %} False {% endif %}): expected string or buffer"} > > > Essentially, I have a role that includes a utility role for sqlplus work. > It somestimes trips on the 'failed_when' statement in the included sqlplus > role. I believe this has something to do with use an include (with > conditional) and then that include also has conditionals, such that they > are mashing together and sometimes breaking the 'template' behind the > scenes. It could also be the scope of registered variable 'expect_output', > which I believe I resolved by declaring 'db_select_output' in role1. > > Any thoughts? It is working right now because I let the 'first time' > failures pass. Now I can't reproduce. I'm worried I have a nasty bug that > will bite me later. Any advice is helpful. > > Thanks! > -- 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 [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/587bc538-3321-47a1-8922-f39e27b4caaf%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
