DEV Community

Roy
Roy

Posted on • Edited on

variable defined in environment not show in ansible_env

- hosts: all                                                                                                                                                                                                       
  become: true                                                                                                                                                                                                     
  environment:                                                                                                                                                                                                     
    HTTPS_PROXY: "{{ HTTP_PROXY }}"                                                                                                                                                                                
    NO_PROXY: "{{ NO_PROXY }}"                                                                                                                                                                                     
  roles:                                                                                                                                                                                                           
  - common   

roles/common/tasks/main.yml

  - name: show https_proxy                                                                                                                                                                                         
    debug:                                                                                                                                                                                                         
      var: ansible_env

result

"ansible_env": {                                                                                                                                                                                               
    "HOME": "/home/vagrant",                                                                                                                                                                                   
    "LANG": "en_US.UTF-8",                                                                                                                                                                                     
    "LOGNAME": "vagrant",                                                                                                                                                                                      
    "MAIL": "/var/mail/vagrant",                                                                                                                                                                               
    "PATH": "/usr/local/bin:/usr/bin:/bin:/usr/games",                                                                                                                                                         
    "PWD": "/home/vagrant", 
    "SHELL": "/bin/bash", 
    "SHLVL": "0", 
    "SSH_CLIENT": "10.0.2.2 42418 22", 
    "SSH_CONNECTION": "10.0.2.2 42418 10.0.2.15 22", 
    "SSH_TTY": "/dev/pts/0", 
    "TERM": "screen-256color", 
    "USER": "vagrant", 
    "XDG_RUNTIME_DIR": "/run/user/1000", 
    "XDG_SESSION_CLASS": "user", 
    "XDG_SESSION_ID": "11", 
    "XDG_SESSION_TYPE": "tty", 
    "_": "/bin/sh"
}

You can use env lookup instead

---
- hosts: localhost
  connection: local

  tasks:
    - debug:
        msg: "{{ lookup('env', 'https_proxy') }}"

Top comments (0)