title: How to use environment variables in Ansible?
body: <p>I have a docker-compose project that I would like to convert to Ansible.</p>
  
  <p>Everything is working fine but I want to convert the command below from docker compose to Ansible.
  I tried to pass (env, envfile command) and it is still not working correctly. This is the command in docker compose</p>
  
  <pre><code>  Environment:
   - NGINX_HOST=http://nginx:80
  </code></pre>
  
  <p>Is there any way to select and use environment variables in Ansible playbook?
  What is the syntax of this command in Ansible ?</p>
  
  <p>my playbook</p>
  
  <pre><code>- hosts: all
    connection: local
    tasks:
  
    - name: 3
      command: docker build --network host -t man /home/my/Documents/2/mysite/
  
    - name: php
      docker_container:
        name: 1-php
        image: php:fpm
        state: started
        volumes:
         - ./file:/var/www/html/x.com
  
    - name: nginx-vts-exporter
      docker_container:
        name: x-Exporter
        image: sophos/nginx-vts-exporter:latest
        state: started
        ports:
         - 9913:9913
  
  
    - name: prom
      docker_container:
        name: x-prometheus
        image: prom/prometheus:latest
        state: started
        ports:
         - 9090:9090
        volumes:
         - ./monitor/prometheus.yml:/etc/prometheus/prometheus.yml
        links:
         - x-Exporter
  
    - name: nginx
      docker_container:
        name: x-Nginx
        image: nginx:latest
        volumes:
          - ./site.conf:/etc/nginx/conf.d/x.conf:ro
          - ./file:/var/www/html/x.com
        ports:
          - 80:80
        links:
          - 1-php
          - x-Exporter
  </code></pre>