Sunday, March 11, 2018

Ansible export: `=': not a valid identifier" Error

Symptom:

 When we try to run sqlplus via ansible yaml file, we hit error like
"stderr": "/bin/sh: line 0: export: `=': not a valid identifier", 
 Part of our yaml file related to export is:

- name: run the sql to get the result
     shell: |
          export ORACLE_SID = {{ mysid }}
          export ORACLE_HOME = {{ dbhome_locl }}
          {{ dbhome_locl }}/bin/sqlplus  "/ as sysdba" @/tmp/ansible_sql.sql "{{ myparameter }}"
     register: sqloutput

Reason:

 Ansible is written by python. Space ' '  is the delimiter. We need to be careful to add ' '  into any our commands which pass into ansible.
 export ORACLE_SID = {{ mysid }}  ---> there is space ' ' after ORACLE_SID, the new commandline ansible generates may confuse SHELL


Solution:

          export ORACLE_SID={{ mysid }}
          export ORACLE_HOME={{ dbhome_locl }}


No space before '='

1 comment:

radha said...

Nice post.Keep sharing Devops Online Course