- hosts: webservers, devservers shell: /path/to/some/script.sh
environment: group_vars
- hosts: devservers shell: /path/to/some/other/script.sh
environment: group_vars
- hosts: webservers shell: /path/script.sh
environment: group_vars
Another question: If a first script runs another script (second) that only exports variables, ansible will interpret the exported variables (from the second script) and they will be available for the rest of the first script ?
Thank you.
Adrian
I’m not sure exactly what you are asking with regards to the playbook syntax, but it is not valid.
To my knowledge, Ansible will not carry exported variables from one shell script to the next, unless you somehow capture them with some conbination of register: and set_fact
--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/4035a18a-aaef-41ab-ab27-e408ebb47d83%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Sorry I misread your second question. To answer it properly, I’m fairly certain that you will get the same behaviour with the shell module as you would running a script from an interactive shell, so sourcing scripts and exporting from a sourced script will work just fine.
With the correct playbook yaml structure, your first example should work just fine - building a dictionary of environment variables then passing it to each task with the environment: keyword.
In your example, I’m not sure where $APP is being set, but you can define variables using other variables in this manner.
- hosts: somegroup
vars:
apps: something
myenv:
ACE: "{{ apps }}/default-ace/ACE"
PIN="{{ apps }}/default-ace/PIN"
APPETIZER="{{ apps }}/default-ace/APPETIZER"
tasks:
- shell: /path/to/script
environment: myenv
- shell: /path/to/other/script
environment: myenv
Other approaches could be to build your environment variables based on group variables or role variables. This makes sense if you are targeting multiple host groups like the example in your first message.
--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/7d346bb9-4bcd-4656-9bf5-1a439d772432%40googlegroups.com.