I am currently trying to automate Oracle Database XE using ansible playbook. Everything with the installation seems to be fine, except for the step in which environment variables for Oracle are set:

source /u01/app/oracle/product/11.2.0/xe/bin/oracle_env.sh

The code in ansible playbook looks like this:

- name: setup oracle environment
  shell: source /u01/app/oracle/product/11.2.0/xe/bin/oracle_env.sh
  shell: reset
  shell: /bin/echo 'source /u01/app/oracle/product/11.2.0/xe/bin/oracle_env.sh' >> /home/vagrant/.bash_profile
- name: create users and schemas on the oracle database
  shell: sqlplus SYSTEM/root@XE @ create_schemas_users.sql

Then, when I run the ansible playbook, at the end of the process, I get something like this:

TASK [create users and schemas on the oracle database] *******************************************************************************************************************************************************************************

fatal: [wemdbc01]: FAILED! => {"changed": true, "cmd": "sqlplus SYSTEM/root@XE @ create_schemas_users.sql", "delta": "0:00:00.002841", "end": "2017-05-30 08:40:50.652786", "failed": true, "rc": 127, "start": "2017-05-30 08:40:50.649945", "stderr": "/bin/sh: sqlplus: command not found", "stderr_lines": ["/bin/sh: sqlplus: command not found"], "stdout": "", "stdout_lines": []}
        to retry, use: --limit @/var/wminst/ansible-config/playbooks/oracle-xe.retry

PLAY RECAP ***************************************************************************************************************************************************************************************************************************

wemdbc01                   : ok=6    changed=2    unreachable=0    failed=1

Connection to closed.

What am I doing wrong? Why after running source /u01/app/oracle/product/11.2.0/xe/bin/oracle_env.sh and resetting the terminal sqlplus is not visible for bash?


The remote shell cannot find the sqlplus program. Find the path of the program on the remote system and try appending it to the PATH variable as the first part of the ansible shell command;

shell: "export PATH=$PATH:/mypath/sqlplus; source /u01/app/oracle/product/11.2.0/xe/bin/oracle_env.sh"
  • you didn't append to the path, you replaced the path ... maybe PATH=$PATH:/mypath/sqlplus ? – Jeff Schaller May 30 '17 at 19:25
  • @JeffSchaller Ah, thanks - yes, that was an omission. Fixed now – einonm May 30 '17 at 19:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.