How to use environment variables in Ansible?Ansible - 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
Did US corporations pay demonstrators in the German demonstrations against article 13?
The One-Electron Universe postulate is true - what simple change can I make to change the whole universe?
Perfect riffle shuffles
Latex for-and in equation
Who must act to prevent Brexit on March 29th?
What is Sitecore Managed Cloud?
Meta programming: Declare a new struct on the fly
What will be the benefits of Brexit?
word describing multiple paths to the same abstract outcome
Can the electrostatic force be infinite in magnitude?
Is exact Kanji stroke length important?
Female=gender counterpart?
How can I successfully establish a nationwide combat training program for a large country?
How do ultrasonic sensors differentiate between transmitted and received signals?
How to check participants in at events?
Is it possible to build a CPA Secure encryption scheme which remains secure even when the encryption of secret key is given?
I'm in charge of equipment buying but no one's ever happy with what I choose. How to fix this?
How will losing mobility of one hand affect my career as a programmer?
How to deal with or prevent idle in the test team?
Would it be legal for a US State to ban exports of a natural resource?
Teaching indefinite integrals that require special-casing
Can I create an upright 7-foot × 5-foot wall with the Minor Illusion spell?
Is there a good way to store credentials outside of a password manager?
Why is delta-v is the most useful quantity for planning space travel?
How to use environment variables in Ansible?
Ansible - 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
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
add a comment |
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
For the enviroment variables of target machine, uselookup('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
add a comment |
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
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
docker docker-compose ansible
edited Mar 7 at 11:18
Tyr_90
asked Mar 7 at 9:39
Tyr_90Tyr_90
166
166
For the enviroment variables of target machine, uselookup('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
add a comment |
For the enviroment variables of target machine, uselookup('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
add a comment |
1 Answer
1
active
oldest
votes
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
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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
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
add a comment |
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
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
add a comment |
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
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
edited Mar 7 at 12:38
answered Mar 7 at 10:38
VelikiiNehochuhaVelikiiNehochuha
1,2981925
1,2981925
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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