seting environment

80 views
Skip to first unread message

coach...@gmail.com

unread,
Dec 14, 2017, 1:43:29 AM12/14/17
to Ansible Project
I have few variables defined in a variable.yml file for example

cat variable.com ( its a dynamic file and the value keeps changing )
ptr_image: my.example.com/jobname/testname
ver_number: v99

I am using this in my playbook ... build.yml

where i am using this file for the variables..

---
- name: to execute the build
  tasks:
  - name: exporting the variables
    include_vars: variable.yml
  - name: running the docker stack
    shell: docket stack -c some.yml ..

    

but while running the command docker stack this variable is not exporting and throws error . Could you please help as to how can i export this variable .
.i have tried environment module environment but its not exporting i am not sure if i am doing it correctly...Thank you
     



coach rhca

unread,
Dec 14, 2017, 8:07:42 AM12/14/17
to ansible...@googlegroups.com
any thoughts or approach in this regard. ....

--
You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/glH8oHQHiC0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-project+unsubscribe@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/6be333d1-917f-49c5-bb97-91cc9b155072%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Kai Stian Olstad

unread,
Dec 14, 2017, 9:59:11 AM12/14/17
to ansible...@googlegroups.com
On Thursday, 14 December 2017 14.07.22 CET coach rhca wrote:
>
> any thoughts or approach in this regard. ....

Check out environments, include vars doesn't export anything to a shell. It only load the variable inside Ansible.


--
Kai Stian Olstad

coach rhca

unread,
Dec 14, 2017, 10:35:30 AM12/14/17
to ansible...@googlegroups.com
thanks Kai, if the include_vars will not export , i have tried the environment module too... the variable file is dynamic and every time it changes the value.
cat variable.yml ( its a dynamic file and the value keeps changing )
ptr_image: my.example.com/jobname/testname  ======>( this value will change frequently )
ver_number: v99  ===> (this values will change frequently in the file say to v100 v101 ....v150 )


so how do we export the change/dynamic  values so that the command docker stack -c somefile.yml runs with the exported variables..when using environment module..please share your insight ...thanks

--
You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/glH8oHQHiC0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-project+unsubscribe@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.

Kai Stian Olstad

unread,
Dec 14, 2017, 10:45:31 AM12/14/17
to ansible...@googlegroups.com
On Thursday, 14 December 2017 16.35.10 CET coach rhca wrote:
>
> thanks Kai, if the include_vars will not export , i have tried the
> environment module too... the variable file is dynamic and every time it
> changes the value.
> cat variable.yml <http://variable.com>( its a dynamic file and the value
> keeps changing )
> ptr_image: my.example.com/jobname/testname ======>( this value will change
> frequently ) <http://my.example.com/jobname/testname>
> ver_number: v99 ===> (this values will change frequently in the file say
> to v100 v101 ....v150 )

Run the include_var but on the shell you need to list all the variables again, then the variables is available in the shell.

- shell: docker..........
environment:
ver_number: '{{ ver_number }}'
...
...
...


--
Kai Stian Olstad

coach rhca

unread,
Dec 14, 2017, 11:58:17 AM12/14/17
to ansible...@googlegroups.com
Thanks Kai for clarifying it...so putting variable under the environment module after shell will export the variable. ..can we see the variable  with echo $ver_number on the linux host if it has been exported using environment



--
Kai Stian Olstad

--
You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/glH8oHQHiC0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-project+unsubscribe@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.

Kai Stian Olstad

unread,
Dec 14, 2017, 12:05:15 PM12/14/17
to ansible...@googlegroups.com
On Thursday, 14 December 2017 17.58.03 CET coach rhca wrote:
>
> Thanks Kai for clarifying it...so putting variable under the environment
> module after shell will export the variable. ..can we see the variable
> with echo $ver_number on the linux host if it has been exported using
> environment

The environment is only for that single task in Ansible, it doesn't do any changes to the system.


--
Kai Stian Olstad

coach rhca

unread,
Dec 14, 2017, 12:56:38 PM12/14/17
to ansible...@googlegroups.com
thanks again kai and appreciate your help...will check it...



--
Kai Stian Olstad

--
You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/glH8oHQHiC0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-project+unsubscribe@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.

Brian Coca

unread,
Dec 14, 2017, 1:20:24 PM12/14/17
to Ansible Project
- name: to execute the build
tasks:
- name: exporting the variables
include_vars:
file: variable.yml
name: myenvvars

- name: running the docker stack
shell: docket stack -c some.yml ..
environment: '{{myenvvars}}'


--
----------
Brian Coca

coach rhca

unread,
Dec 15, 2017, 2:26:31 AM12/15/17
to ansible...@googlegroups.com
Thanks a ton  Brian for the help...

--
You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/glH8oHQHiC0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-project+unsubscribe@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.

coach rhca

unread,
Dec 20, 2017, 10:45:16 PM12/20/17
to ansible...@googlegroups.com
sorry for coming back to this again...if we have multiple vars file will the logic be the same....for example ..

include_vars:
        file: {{item}} (rather than one file variable.yml)
        with_items:
                 - variable1.yml
                 - variable2.yml
                 - variable3.yml
        name: myenvvars
        

  - name: running the docker stack
    shell: docket stack -c some.yml ..
    environment: '{{myenvvars}}'

please can you share the insight ...

coach rhca

unread,
Dec 22, 2017, 1:53:15 AM12/22/17
to ansible...@googlegroups.com
Kai/Brian, could you please help on it...as above the files are variable1.yml, variable2.yml,variable3.yml....having the values as ptr_image: my.example.com/jobname/testname
ver_number: v99 and diferent values in different files but the variable name ( ptr_image and ver_number  name remains the same in all files but values change) ...is there a way that we can export the environment variable from file variable1.yml and run the docker stack -c some.yml and then take the variable2 file and export the environment variable again from this file and then again run docket stack -c some.yml and so on...( one variable file values to be export and subsequent ones)....

thanks 

coach rhca

unread,
Dec 22, 2017, 11:08:26 AM12/22/17
to ansible...@googlegroups.com
any thoughts on this...

Brian Coca

unread,
May 30, 2018, 11:56:23 PM5/30/18
to Ansible Project
yes, just you are indenting things wrong and name is a label, not the
same as register:


- include_vars:
file: {{item}} (rather than one file variable.yml)
with_items:
- variable1.yml
- variable2.yml
- variable3.yml
register: myenvvars

----------
Brian Coca

coach rhca

unread,
May 31, 2018, 6:24:49 AM5/31/18
to ansible...@googlegroups.com
thank you Brian


----------
Brian Coca

--
You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/glH8oHQHiC0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-project+unsubscribe@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages