# Remote Env Setup Queries

**URL:** <https://forum.ansible.com/t/remote-env-setup-queries/23433>\
**Category:** Ansible Developer\
**Created:** [January 11, 2017, 12:54pm UTC](https://forum.ansible.com/t/remote-env-setup-queries/23433 "2017-01-11T12:54:22Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![John\_Patrick](https://avatars.discourse-cdn.com/v4/letter/j/7feea3/32.png) [@John\_Patrick](https://forum.ansible.com/u/John_Patrick)\
**Post date:** [January 11, 2017, 12:54pm UTC](https://forum.ansible.com/t/remote-env-setup-queries/23433/1 "2017-01-11T12:54:22Z")

</div>

I’m working on a custom module but having issues with the environment setup on the remote server.

How should the remote environment variables be correctly setup. I’ve been looking here [http://docs.ansible.com/ansible/dev\_guide/developing\_modules.html](http://docs.ansible.com/ansible/dev_guide/developing_modules.html) but not found anything yet or I might have simply missed it.

At the moment I’m doing a shell task, along the lines of “. PATH/env.sh && myscript.py”, also doing sudo: yes, sudo\_user: “{{ remote\_user }}”

Ideally I’ld like to know how I can specify PATH as a field for my module, then before the module executes on the target server the env.sh is executes before the actual task.

Or if people know another module which does similar I don’t mine reviewing that and working it out for myself. I just can’t figure out how to source the shell script beforehand.

Cheers,  
John

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [January 12, 2017, 6:07am UTC](https://forum.ansible.com/t/remote-env-setup-queries/23433/2 "2017-01-12T06:07:15Z")

</div>

The environment: directive exists so each module does not need to implement what you are asking.

---

<div class="post-metadata">

**Author:** ![John\_Patrick](https://avatars.discourse-cdn.com/v4/letter/j/7feea3/32.png) [@John\_Patrick](https://forum.ansible.com/u/John_Patrick)\
**Post date:** [January 12, 2017, 11:53am UTC](https://forum.ansible.com/t/remote-env-setup-queries/23433/3 "2017-01-12T11:53:14Z")

</div>

Where can I find a list of all the options that environment allows and how to use it correctly?

I’ve found this [http://docs.ansible.com/ansible/playbooks\_environment.html](http://docs.ansible.com/ansible/playbooks_environment.html)

What I’m trying to do is specify a script to execute which will setup the enviroment prior to execution, but that is either not an option or I just can’t find the documentation.

Cheers,  
John

---

<div class="post-metadata">

**Author:** ![John\_Patrick](https://avatars.discourse-cdn.com/v4/letter/j/7feea3/32.png) [@John\_Patrick](https://forum.ansible.com/u/John_Patrick)\
**Post date:** [January 12, 2017, 11:57am UTC](https://forum.ansible.com/t/remote-env-setup-queries/23433/4 "2017-01-12T11:57:52Z")

</div>

What I’m hoping to find it something like this;

$ cat play.yml

- hosts: localhost  
tasks:

- name: Test that my module works  
MY\_CUSTOM\_MODULE:  
register: result  
environment:  
script: ${WL\_HOME}/server/bin/setWLSEnv.sh

- debug: var=result  
$

but script doesn’t work, so not sure what it should be. It might be environment lacks this ability.

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [January 12, 2017, 6:32pm UTC](https://forum.ansible.com/t/remote-env-setup-queries/23433/5 "2017-01-12T18:32:43Z")

</div>

It is for setting environment variables, it should not execute anything.

---

<div class="post-metadata">

**Author:** ![John\_Patrick](https://avatars.discourse-cdn.com/v4/letter/j/7feea3/32.png) [@John\_Patrick](https://forum.ansible.com/u/John_Patrick)\
**Post date:** [January 12, 2017, 8:00pm UTC](https://forum.ansible.com/t/remote-env-setup-queries/23433/6 "2017-01-12T20:00:19Z")

</div>

Is their anyway I can get environment to source a shell script?

Also from within a custom module how do I define default environment variables? e.g. the user defines a base dir and the module defines various variables based upon the user provided value?

---

<div class="post-metadata">

**Author:** ![John\_Patrick](https://avatars.discourse-cdn.com/v4/letter/j/7feea3/32.png) [@John\_Patrick](https://forum.ansible.com/u/John_Patrick)\
**Post date:** [January 13, 2017, 11:00am UTC](https://forum.ansible.com/t/remote-env-setup-queries/23433/7 "2017-01-13T11:00:35Z")

</div>

If I execute $ . ${WL\_HOME}/server/bin/setWLSEnv.sh  
I get 36 new and 2 modified environment variables, ideally I don’t want the consumer of my custom module to not have to specifiy these manually. I would like the consumer to specify WL\_HOME, then get the ansible module framework to execute ${WL\_HOME}/server/bin/setWLSEnv.sh

If ansible isn’t able to do this, I’ll try and find a work around. But it might be a useful feature for something like environment\_source, so it sources the scripts listed. Or maybe like unsafe where you can do source and it will source the file not define it.

John

---

<div class="post-metadata">

**Author:** ![Anand\_Dasari](https://avatars.discourse-cdn.com/v4/letter/a/f475e1/32.png) [@Anand\_Dasari](https://forum.ansible.com/u/Anand_Dasari)\
**Post date:** [January 17, 2017, 3:53pm UTC](https://forum.ansible.com/t/remote-env-setup-queries/23433/8 "2017-01-17T15:53:17Z")

</div>

Hi John  
Did u find a solution setting up env on target machine using setWLSEnv.sh  
I’m struggling too, if you have solved this , can you please help me?

thanks  
Anand
