ansible 2.0.1 environement variables of remote host

environment variables- Hello , i use ansible to run tasks in remote machine , i want to work with variables from this remote machine . i tried to use lookup module but it return the variables of my machine to the remote one . i have no idea haw to do it .
  • |
    i itried to use “{{ ansible_env.PATH }}” but it return the PATH of my machine . i want to have the PATH of the remote host mentioned in the file /etc/ansible/hosts not the Path of my machine in which i installed ansible
    |

    • |
  • thanks in advance.

ANSIBLE VERSION- 2.0.1
CONFIGURATION- /etc/ansible/ansible.cfg (configuration)
  • /etc/ansible/hosts (list of remote hosts)
OS / ENVIRONMENT- CentOS 7

ansible_env reflects the facts on the machine you gathered facts on, so if it is showing localhost values, you ONLY gathered facts on localhost.

this should show the path for EACH machine:

hosts: all
tasks:

  • debug: msg=“{{ansible_env.PATH}}”

so , i must gather facts off all hosts , that’s the solution ?

no, just on the hosts you want to use facts from.

to work with the PATH of the remote host i add those lines to my playbook ?

  • gather_facts: yes
    vars:

PTH : “{{ansible_env.PATH}}”

is that correct ?
thank you in advance .
i’ m a begginer at ansible .