ansible playbook permission error when running the command “. oraenv”
Here is the code:
setup new env
command: “. /usr/local/bin/oraenv”
Here is the error:
TASK [ansible-oracle-patching : command] ************************************************************************************************************************
fatal: [vmcwy60158.prod.acxiom.net ]: FAILED! => {“changed”: false, “cmd”: “. /usr/local/bin/oraenv”, “msg”: “[Errno 13] Permission denied”, “rc”: 13}
But I can run other commands with elevated privileges
can anybody help please ?
Karl_Auer
(Karl Auer)
June 26, 2018, 3:53pm
2
It looks like you are trying to source that file rather than execute it, presumably in order to set environment variables. That probably won’t work, as the environment variables will not survive the death of the shell you ran.
Re the permissions issue: I’m not sure, but you may be attempting to execute “.” (a directory) and that would get you “permission denied”. Not sure how command works, so that might well be BS
Regards, K.
ok forget about the permission error, I am trying to change my environment to ASM environment with this commands
ORAENV_ASK=NO
export ORACLE_SID=+ASM
. oraenv
ASK [ansible-oracle-patching : changing to ASM environment] ****************************************************************************************************
changed: [vmcwy60158.prod.acxiom.net ] => (item=ORAENV_ASK=NO)
changed: [vmcwy60158.prod.acxiom.net ] => (item=export ORACLE_SID=+ASM)
failed: [vmcwy60158.prod.acxiom.net ] (item=. oraenv) => {“changed”: true, “cmd”: “. oraenv”, “delta”: “0:00:00.002241”, “end”: “2018-06-26 11:31:10.927354”, “ite m”: “. oraenv”, “msg”: “non-zero return code”, “rc”: 1, “start”: “2018-06-26 11:31:10.925113”, “stderr”: “/bin/sh: line 0: .: oraenv: file not found”, “stderr_li nes”: [“/bin/sh: line 0: .: oraenv: file not found”], “stdout”: “”, “stdout_lines”: }
Karl_Auer
(Karl Auer)
June 26, 2018, 5:02pm
4
Post your whole playbook; it’s hard to tell what’s actually happening.
I don’t think I can help, but if you post everything maybe someone else can.
Regards, K.
You need to specify any environment variables using the ‘environment’ keyword on your command.
see https://docs.ansible.com/ansible/latest/reference_appendices/faq.html#how-can-i-set-the-path-or-any-other-environment-variable-for-a-task-or-entire-playbook
In my experience it can be fiddly getting environment set correctly for commands so that you can run things such as sqlplus, which needed several environment variables to be set before it would work.
I wound up setting something like this in my group_vars:
oracle_environment:
LD_LIBRARY_PATH: ‘/opt/app/oracle/product/db11gR2_1/lib’
ORACLE_BASE: ‘/opt/app/oracle’
TNS_ADMIN: ‘/opt/app/oracle/common/network/admin’
PATH: “{{ ansible_env.PATH}}:/opt/app/oracle/product/db11gR2_1/bin:/usr/local/bin:/bin:/usr/bin:.:/sbin”
ORACLE_HOME: ‘/opt/app/oracle/product/db11gR2_1’
NLS_DATE_FORMAT: ‘DD-MON-YYYY HH24:MI:SS’
and then using something like the following to run sqlplus.
name: test sqlplus
shell: sqlplus -L {{ oracle_user }}/{{ oracle_cred }}@{{ oracle_host }}/{{ oracle_tns }} @TESTS /Ensure_Connection.sql
args:
chdir: database_scripts
executable: /bin/bash
environment: “{{ oracle_environment }}”
register: sqlplus_result
name: show sqlplus result
debug:
var: sqlplus_result
Hope this helps,
Jon
Thank you very much Jon. That helped.