seting environment

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…

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.

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

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 }}'
    ...
    ...
    ...

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.

thanks again kai and appreciate your help…will check it…

- 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}}'

Thanks a ton Brian for the help…

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 …

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

any thoughts on this…

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

thank you Brian