How to use environment variables in Ansible?2019 Community Moderator ElectionAnsible - accessing local environment variablesHow is Docker different from a virtual machine?Should I use Vagrant or Docker for creating an isolated environment?How to get a Docker container's IP address from the host?How to remove old Docker containersHow to correctly link php-fpm and Nginx Docker containers?How do I pass environment variables to Docker containers?Connecting to container using ansibleCan't load prometheus.yml config file with docker (prom/prometheus)Nginx vts exporter connection refusednginx is not working with ansible playbook

Why does Deadpool say "You're welcome, Canada," after shooting Ryan Reynolds in the end credits?

What is the difference between "shut" and "close"?

Excess Zinc in garden soil

Unreachable code, but reachable with exception

Why do Australian milk farmers need to protest supermarkets' milk price?

Best mythical creature to use as livestock?

How to discourage/prevent PCs from using door choke-points?

Should we release the security issues we found in our product as CVE or we can just update those on weekly release notes?

Is all copper pipe pretty much the same?

Replacing Windows 7 security updates with anti-virus?

My story is written in English, but is set in my home country. What language should I use for the dialogue?

What is the definition of "Natural Selection"?

Rejected in 4th interview round citing insufficient years of experience

Is it illegal in Germany to take sick leave if you caused your own illness with food?

"One can do his homework in the library"

What wound would be of little consequence to a biped but terrible for a quadruped?

Can "semicircle" be used to refer to a part-circle that is not a exact half-circle?

Single word request: Harming the benefactor

Question about partial fractions with irreducible quadratic factors

How to deal with a cynical class?

Is having access to past exams cheating and, if yes, could it be proven just by a good grade?

Want to switch to tankless, but can I use my existing wiring?

Provisioning profile doesn't include the application-identifier and keychain-access-groups entitlements

Who is our nearest neighbor



How to use environment variables in Ansible?



2019 Community Moderator ElectionAnsible - accessing local environment variablesHow is Docker different from a virtual machine?Should I use Vagrant or Docker for creating an isolated environment?How to get a Docker container's IP address from the host?How to remove old Docker containersHow to correctly link php-fpm and Nginx Docker containers?How do I pass environment variables to Docker containers?Connecting to container using ansibleCan't load prometheus.yml config file with docker (prom/prometheus)Nginx vts exporter connection refusednginx is not working with ansible playbook










1















I have a docker-compose project that I would like to convert to Ansible.



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



 Environment:
- NGINX_HOST=http://nginx:80


Is there any way to select and use environment variables in Ansible playbook?
What is the syntax of this command in Ansible ?



my playbook



- 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









share|improve this question









New contributor




Tyr_90 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • For the enviroment variables of target machine, use lookup('env', 'NGINX_HOST') . For the ones of source, see this post: stackoverflow.com/questions/21422158/…

    – vahdet
    Mar 7 at 9:44











  • i need to use it with docker ... tried to use the syntax in the answer and it didn't work

    – Tyr_90
    Mar 7 at 9:52















1















I have a docker-compose project that I would like to convert to Ansible.



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



 Environment:
- NGINX_HOST=http://nginx:80


Is there any way to select and use environment variables in Ansible playbook?
What is the syntax of this command in Ansible ?



my playbook



- 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









share|improve this question









New contributor




Tyr_90 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • For the enviroment variables of target machine, use lookup('env', 'NGINX_HOST') . For the ones of source, see this post: stackoverflow.com/questions/21422158/…

    – vahdet
    Mar 7 at 9:44











  • i need to use it with docker ... tried to use the syntax in the answer and it didn't work

    – Tyr_90
    Mar 7 at 9:52













1












1








1








I have a docker-compose project that I would like to convert to Ansible.



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



 Environment:
- NGINX_HOST=http://nginx:80


Is there any way to select and use environment variables in Ansible playbook?
What is the syntax of this command in Ansible ?



my playbook



- 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









share|improve this question









New contributor




Tyr_90 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












I have a docker-compose project that I would like to convert to Ansible.



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



 Environment:
- NGINX_HOST=http://nginx:80


Is there any way to select and use environment variables in Ansible playbook?
What is the syntax of this command in Ansible ?



my playbook



- 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






docker docker-compose ansible






share|improve this question









New contributor




Tyr_90 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




Tyr_90 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited Mar 7 at 11:18







Tyr_90













New contributor




Tyr_90 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked Mar 7 at 9:39









Tyr_90Tyr_90

166




166




New contributor




Tyr_90 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Tyr_90 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Tyr_90 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












  • For the enviroment variables of target machine, use lookup('env', 'NGINX_HOST') . For the ones of source, see this post: stackoverflow.com/questions/21422158/…

    – vahdet
    Mar 7 at 9:44











  • i need to use it with docker ... tried to use the syntax in the answer and it didn't work

    – Tyr_90
    Mar 7 at 9:52

















  • For the enviroment variables of target machine, use lookup('env', 'NGINX_HOST') . For the ones of source, see this post: stackoverflow.com/questions/21422158/…

    – vahdet
    Mar 7 at 9:44











  • i need to use it with docker ... tried to use the syntax in the answer and it didn't work

    – Tyr_90
    Mar 7 at 9:52
















For the enviroment variables of target machine, use lookup('env', 'NGINX_HOST') . For the ones of source, see this post: stackoverflow.com/questions/21422158/…

– vahdet
Mar 7 at 9:44





For the enviroment variables of target machine, use lookup('env', 'NGINX_HOST') . For the ones of source, see this post: stackoverflow.com/questions/21422158/…

– vahdet
Mar 7 at 9:44













i need to use it with docker ... tried to use the syntax in the answer and it didn't work

– Tyr_90
Mar 7 at 9:52





i need to use it with docker ... tried to use the syntax in the answer and it didn't work

– Tyr_90
Mar 7 at 9:52












1 Answer
1






active

oldest

votes


















0














if you use variable from vars. You can use syntax like this "repo", also key for environment variables is env, not Environment.



- hosts: fix
remote_user: root
vars:
repo: test
tasks:
- name: prom
docker_container
env:
REPO: "repo"
HOSTIP: " ansible_eth0.ipv4.address "
NGINX_HOST: http://nginx:80





share|improve this answer

























  • i have added my playbook so you can see what i mean .... the exporter is not reaching the nginx image for that i want to add the environment command , can you edit it so it can reach end ecport metrics ?

    – Tyr_90
    Mar 7 at 11:19












  • Yes, updated, into docker_container section, you can put "env" sub section and place there, your environment variables

    – VelikiiNehochuha
    Mar 7 at 12:28












  • you mean like ................... vars: NGINX_HOST: nginx:80 if not can you edit you'r post and put the code in it

    – Tyr_90
    Mar 7 at 12:30












  • You can not used vars and just put string NGINS_HOST: "host"

    – VelikiiNehochuha
    Mar 7 at 12:32











  • It worked thank u so much

    – Tyr_90
    Mar 7 at 12:40










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);






Tyr_90 is a new contributor. Be nice, and check out our Code of Conduct.









draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55040500%2fhow-to-use-environment-variables-in-ansible%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














if you use variable from vars. You can use syntax like this "repo", also key for environment variables is env, not Environment.



- hosts: fix
remote_user: root
vars:
repo: test
tasks:
- name: prom
docker_container
env:
REPO: "repo"
HOSTIP: " ansible_eth0.ipv4.address "
NGINX_HOST: http://nginx:80





share|improve this answer

























  • i have added my playbook so you can see what i mean .... the exporter is not reaching the nginx image for that i want to add the environment command , can you edit it so it can reach end ecport metrics ?

    – Tyr_90
    Mar 7 at 11:19












  • Yes, updated, into docker_container section, you can put "env" sub section and place there, your environment variables

    – VelikiiNehochuha
    Mar 7 at 12:28












  • you mean like ................... vars: NGINX_HOST: nginx:80 if not can you edit you'r post and put the code in it

    – Tyr_90
    Mar 7 at 12:30












  • You can not used vars and just put string NGINS_HOST: "host"

    – VelikiiNehochuha
    Mar 7 at 12:32











  • It worked thank u so much

    – Tyr_90
    Mar 7 at 12:40















0














if you use variable from vars. You can use syntax like this "repo", also key for environment variables is env, not Environment.



- hosts: fix
remote_user: root
vars:
repo: test
tasks:
- name: prom
docker_container
env:
REPO: "repo"
HOSTIP: " ansible_eth0.ipv4.address "
NGINX_HOST: http://nginx:80





share|improve this answer

























  • i have added my playbook so you can see what i mean .... the exporter is not reaching the nginx image for that i want to add the environment command , can you edit it so it can reach end ecport metrics ?

    – Tyr_90
    Mar 7 at 11:19












  • Yes, updated, into docker_container section, you can put "env" sub section and place there, your environment variables

    – VelikiiNehochuha
    Mar 7 at 12:28












  • you mean like ................... vars: NGINX_HOST: nginx:80 if not can you edit you'r post and put the code in it

    – Tyr_90
    Mar 7 at 12:30












  • You can not used vars and just put string NGINS_HOST: "host"

    – VelikiiNehochuha
    Mar 7 at 12:32











  • It worked thank u so much

    – Tyr_90
    Mar 7 at 12:40













0












0








0







if you use variable from vars. You can use syntax like this "repo", also key for environment variables is env, not Environment.



- hosts: fix
remote_user: root
vars:
repo: test
tasks:
- name: prom
docker_container
env:
REPO: "repo"
HOSTIP: " ansible_eth0.ipv4.address "
NGINX_HOST: http://nginx:80





share|improve this answer















if you use variable from vars. You can use syntax like this "repo", also key for environment variables is env, not Environment.



- hosts: fix
remote_user: root
vars:
repo: test
tasks:
- name: prom
docker_container
env:
REPO: "repo"
HOSTIP: " ansible_eth0.ipv4.address "
NGINX_HOST: http://nginx:80






share|improve this answer














share|improve this answer



share|improve this answer








edited Mar 7 at 12:38

























answered Mar 7 at 10:38









VelikiiNehochuhaVelikiiNehochuha

1,2951925




1,2951925












  • i have added my playbook so you can see what i mean .... the exporter is not reaching the nginx image for that i want to add the environment command , can you edit it so it can reach end ecport metrics ?

    – Tyr_90
    Mar 7 at 11:19












  • Yes, updated, into docker_container section, you can put "env" sub section and place there, your environment variables

    – VelikiiNehochuha
    Mar 7 at 12:28












  • you mean like ................... vars: NGINX_HOST: nginx:80 if not can you edit you'r post and put the code in it

    – Tyr_90
    Mar 7 at 12:30












  • You can not used vars and just put string NGINS_HOST: "host"

    – VelikiiNehochuha
    Mar 7 at 12:32











  • It worked thank u so much

    – Tyr_90
    Mar 7 at 12:40

















  • i have added my playbook so you can see what i mean .... the exporter is not reaching the nginx image for that i want to add the environment command , can you edit it so it can reach end ecport metrics ?

    – Tyr_90
    Mar 7 at 11:19












  • Yes, updated, into docker_container section, you can put "env" sub section and place there, your environment variables

    – VelikiiNehochuha
    Mar 7 at 12:28












  • you mean like ................... vars: NGINX_HOST: nginx:80 if not can you edit you'r post and put the code in it

    – Tyr_90
    Mar 7 at 12:30












  • You can not used vars and just put string NGINS_HOST: "host"

    – VelikiiNehochuha
    Mar 7 at 12:32











  • It worked thank u so much

    – Tyr_90
    Mar 7 at 12:40
















i have added my playbook so you can see what i mean .... the exporter is not reaching the nginx image for that i want to add the environment command , can you edit it so it can reach end ecport metrics ?

– Tyr_90
Mar 7 at 11:19






i have added my playbook so you can see what i mean .... the exporter is not reaching the nginx image for that i want to add the environment command , can you edit it so it can reach end ecport metrics ?

– Tyr_90
Mar 7 at 11:19














Yes, updated, into docker_container section, you can put "env" sub section and place there, your environment variables

– VelikiiNehochuha
Mar 7 at 12:28






Yes, updated, into docker_container section, you can put "env" sub section and place there, your environment variables

– VelikiiNehochuha
Mar 7 at 12:28














you mean like ................... vars: NGINX_HOST: nginx:80 if not can you edit you'r post and put the code in it

– Tyr_90
Mar 7 at 12:30






you mean like ................... vars: NGINX_HOST: nginx:80 if not can you edit you'r post and put the code in it

– Tyr_90
Mar 7 at 12:30














You can not used vars and just put string NGINS_HOST: "host"

– VelikiiNehochuha
Mar 7 at 12:32





You can not used vars and just put string NGINS_HOST: "host"

– VelikiiNehochuha
Mar 7 at 12:32













It worked thank u so much

– Tyr_90
Mar 7 at 12:40





It worked thank u so much

– Tyr_90
Mar 7 at 12:40












Tyr_90 is a new contributor. Be nice, and check out our Code of Conduct.









draft saved

draft discarded


















Tyr_90 is a new contributor. Be nice, and check out our Code of Conduct.












Tyr_90 is a new contributor. Be nice, and check out our Code of Conduct.











Tyr_90 is a new contributor. Be nice, and check out our Code of Conduct.














Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55040500%2fhow-to-use-environment-variables-in-ansible%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to get text form Clipboard with JavaScript in Firefox 56?How to validate an email address in JavaScript?How do JavaScript closures work?How do I remove a property from a JavaScript object?How do you get a timestamp in JavaScript?How do I copy to the clipboard in JavaScript?How do I include a JavaScript file in another JavaScript file?Get the current URL with JavaScript?How to replace all occurrences of a string in JavaScriptHow to check whether a string contains a substring in JavaScript?How do I remove a particular element from an array in JavaScript?

Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme

Thal And Out Agency railway station See also References External links Navigation menuOfficial Web Site of Pakistan RailwaysArchivedOfficial Web Site of Pakistan Railwayseeexpanding ite