how to access variables set on target env

Hi

i have a shell script which is setWLSEnv.sh on target machine, i run this first to set up web logic env
after that i run the command
java weblogic.WLST {{ pyhton file}}
now i get Error: could not find or load main class web logic.WLST
why i’m loosing the env variable set in previous command by running setWLSEnv.sh ?
my code is like this ,can somebody help me please

pre_tasks:

  • name: set up web logic env
    command: /usr/bin/sh /path/setWLSEnv.sh

roles:
role: …/roles/deploy_app

deploy_app role contains this

command: "java weblogic.WLST {{python file }}

Hi,

The shell variables set in the setWLSEnv.sh are not persisted between ansible tasks. You can try execute both scripts in the same shell:

  • shell: source /setWLSEnv.sh && java weblogic.WLST {{ python file }}

Regards,

Rui Alves

Each task has its own environment, so what your setting by running a shell script is lost afterwards, hence your error.

You can define environment variables for a task: http://docs.ansible.com/ansible/playbooks_environment.html

If that setWLSEnv.sh contains many vars then store all of them in one ansible var for easy reuse and less clutter.

Dick

I would suggest setting the variables in the host_vars for the target
host. Maybe even encrypted with ansible_vault, if the contain sensible
information.

Johannes