title: How to set different environment variables for each managed host in ansible
body: <p>i have an inventory file which looks like below.</p>
  <pre><code>[abc]
  dsad1.jkas.com
  dsad2.jkas.com
  [def]
  dsad3.jkas.com
  dsad4.jkas.com
  [main:children]
  abc
  def
  [main:vars]
  ansible_user=&quot;{{lookup('env', 'uid')}}
  ansible_password=&quot;{{lookup('env', 'pwd')}}
  ansible_connection=paramkio
  
  
  main.yaml --&gt; main yaml looks like below
  
  ---
  - hosts: &quot;{{my-hosts}}&quot;
    roles:
    - role: dep-main
      tags:
      - main
    - role: dep-test
      tags:
      -test
  
  cat roles/dep-main/tasks/main.yaml
  - name: run playbook
    script: path/scripts/dep-main.sh
  </code></pre>
  <p>where i have scripts folder inside which i have dep-main.sh --&gt; using script module to run the shell script  on remote machine.</p>
  <pre><code> &quot;ansible-playbook -i inventory -e &quot;my_hosts=main&quot; --tags main main.yaml&quot;
  </code></pre>
  <p>i am following above design for a new requirement. Now the challenge is i need to set environment variable for each host and env variables are diff for each host. how can i achieve it . please help me.</p>
  <p>there are around 15 env key value pairs that needs to be exported to each host above, out of which 10 are common, where i'll simply put in the above shell script. where as other 5 env key value pairs are diff for each host like below.</p>
  <pre><code>     dsad1.jkas.com
          sys=abc1
          cap=rty2
          jam=yup4
          pak=hyd4
           jum=563
  
        
  dsad2.jkas.com
   sys=abc45
   cap=hju
   jam=upy
   pak=upsc
   jum=y78
  
           
  </code></pre>
  <p>please help.</p>