# How set 2 environment (PATH and proxy\_env ) in ansible-playbook?

**URL:** <https://forum.ansible.com/t/how-set-2-environment-path-and-proxy-env-in-ansible-playbook/28938>\
**Category:** Ansible Developer\
**Tags:** kubernetes\
**Created:** [November 4, 2018, 1:18pm UTC](https://forum.ansible.com/t/how-set-2-environment-path-and-proxy-env-in-ansible-playbook/28938 "2018-11-04T13:18:17Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![user91](https://avatars.discourse-cdn.com/v4/letter/u/a8b319/32.png) [@user91](https://forum.ansible.com/u/user91)\
**Post date:** [November 4, 2018, 1:18pm UTC](https://forum.ansible.com/t/how-set-2-environment-path-and-proxy-env-in-ansible-playbook/28938/1 "2018-11-04T13:18:17Z")

</div>

Hello!  
Trying to install run ansible-playbook (kubespray) through a proxy.

Here specify the proxy server: [https://github.com/kubernetes-incubator/kubespray/blob/master/inventory/sample/group\_vars/all/all.yml#L52](https://github.com/kubernetes-incubator/kubespray/blob/master/inventory/sample/group_vars/all/all.yml#L52)

Added to the longing Install packages requirements for bootstrap

`environment: "{{proxy_env}}"`

[https://github.com/kubernetes-incubator/kubespray/blob/master/roles/bootstrap-os/tasks/bootstrap-centos.yml#L24](https://github.com/kubernetes-incubator/kubespray/blob/master/roles/bootstrap-os/tasks/bootstrap-centos.yml#L24)

Throws an error

`  
Trying other mirror.

`

If a yaml file to do this task

`

- name: echo Variables  
shell: “echo $http\_proxy $https\_proxy”  
register: shell\_echo\_proxy  
environment: “{{proxy\_env}}”

- debug:  
var: shell\_echo\_proxy.stdout  
`

The will here is such a mistake:

`  
The field ‘environment’ has an invalid value, which includes an undefined variable. The error was: ‘ansible.vars.hostvars.HostVarsVars object’ has no attribute ‘ansible\_default\_ipv4’

The error appears to have been in ‘/home/user/kubespray/roles/bootstrap-os/tasks/bootstrap-centos.yml’: line 17, column 3, but may  
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

- name: echo Variables  
^ here  
`

Try other code

`

- name: echo Variables  
shell: “echo $http\_proxy $https\_proxy”  
register: shell\_echo\_proxy  
environment:

- PATH: “/sbin:/usr/sbin:{{ ansible\_env.PATH }}”  
“{{proxy\_env}}”

- debug:  
var: shell\_echo\_proxy.stdout

TASK [bootstrap-os : include\_tasks] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
Sunday 04 November 2018 19:11:37 +0600 (0:00:00.185) 0:00:08.531 \*\*\*\*\*\*\*  
fatal: [kuber1]: FAILED! =\> {“reason”: “Syntax Error while loading YAML.\n expected , but found ‘?’\n\nThe error appears to have been in ‘/home/user/kubespray/roles/bootstrap-os/tasks/bootstrap-centos.yml’: line 22, column 5, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n - PATH: "/sbin:/usr/sbin:{{ ansible\_env.PATH }}"\n proxy\_env: "{{proxy\_env}}"\n ^ here\nWe could be wrong, but this one looks like it might be an issue with\nmissing quotes. Always quote template expression brackets when they\nstart a value. For instance:\n\n with\_items:\n - {{ foo }}\n\nShould be written as:\n\n with\_items:\n - "{{ foo }}"\n”}

`

Try other code

`

- name: echo Variables

shell: “echo $http\_proxy $https\_proxy”  
register: shell\_echo\_proxy  
environment:

- PATH: “/sbin:/usr/sbin:{{ ansible\_env.PATH }}”

- proxy\_env: “{{proxy\_env}}”

- debug:  
var: shell\_echo\_proxy.stdout

TASK [bootstrap-os : debug] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
Sunday 04 November 2018 19:09:05 +0600 (0:00:02.309) 0:00:15.026 \*\*\*\*\*\*\*  
ok: [kuber3] =\> {  
“shell\_echo\_proxy.stdout”: “”  
}  
ok: [kuber1] =\> {  
“shell\_echo\_proxy.stdout”: “”  
}  
ok: [kuber2] =\> {  
“shell\_echo\_proxy.stdout”: “”  
}

`

Try other code

`

- name: echo Variables  
shell: “echo $http\_proxy $https\_proxy”  
register: shell\_echo\_proxy  
environment: {PATH: “{{ ansible\_env.PATH }}:{{ bin\_dir }}”,“{{proxy\_env}}”}

- debug:  
var: shell\_echo\_proxy.stdout

TASK [bootstrap-os : echo Variables] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
Sunday 04 November 2018 19:13:39 +0600 (0:00:01.830) 0:00:12.664 \*\*\*\*\*\*\*  
fatal: [kuber1]: FAILED! =\> {“changed”: false, “module\_stderr”: “Shared connection to 172.16.149.93 closed.\r\n”, “module\_stdout”:  
“/bin/sh: {{proxy\_env}}=None: command not found\r\n”, “msg”: “MODULE FAILURE”, “rc”: 127}

`

Try other code

`

- name: echo Variables  
shell: “echo $http\_proxy $https\_proxy”  
register: shell\_echo\_proxy  
vars:  
“{{proxy\_env}}”  
environment:

- PATH: “/sbin:/usr/sbin:{{ ansible\_env.PATH }}”

- debug:  
var: shell\_echo\_proxy.stdout

TASK [bootstrap-os : include\_tasks] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
Sunday 04 November 2018 19:16:49 +0600 (0:00:00.192) 0:00:08.732 \*\*\*\*\*\*\*  
fatal: [kuber1]: FAILED! =\> {“reason”: “Vars in a Task must be specified as a dictionary, or a list of dictionaries\n\nThe error appears to have been in ‘/home/user/kubespray/roles/bootstrap-os/tasks/bootstrap-centos.yml’: line 21, column 5, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n vars:\n "{{proxy\_env}}"\n ^ here\nWe could be wrong, but this one looks like it might be an issue with\nmissing quotes. Always quote template expression brackets when they\nstart a value. For instance:\n\n with\_items:\n - {{ foo }}\n\nShould be written as:\n\n with\_items:\n - "{{ foo }}"\n”}  
fatal: [kuber2]: FAILED! =\> {“reason”: "Vars in a Task must be specified as a dictionary, or a li

`
