Dear all,
I’m using AWX and Ansible 2.5. At the moment I’m trying to automate the deployment of an application that used maven to parametrize the setting of the application with a tokens file. The variables should be stored in the Anisble Inventory and the token files should be created with Jinja2 templates and the templates module.
Inventory structure:
- hostsfile [Contains hosts]
- group_vars/application1 [Contains application1 group vars]
- group_vars/application1-forms [Contains application1-forms group vars]
- group_vars/application1-services [Contains application1-servcices group vars]
[application1:children]
application1-forms
application1-services
[application1-forms]
forms_node1
[application1-services]
services_node1
- hosts: application1
gather_facts: no
tasks: - name: Include and launch MAVEN deployment role
delegate_to: “{{ maven_host }}”
import_role:
name: roles/application1/maven
vars:
template_files: - {component: application1-forms, file: tokens-local.properties }
- {component: application1-services, file: tokens-local.properties }
The Role:
- name: Generate Token files.
template:
src: “…/templates/{{ item.component }}/tokens/{{ item.file }}.j2”
dest: “{{ mvn_dir }}/{{ item.component }}/conf/tokens/{{ item.file }}”
owner: maven
group: maven
mode: 0775
with_items: “{{ template_files }}”
run_once: True
When the role execution is delegated from forms_node1 to maven_host, the template module can access only to the variables defined in application1, and application1-forms files. When the role execution is delegated from services_node1 to maven_host, the template module can access only to the variables defined in application1, and application1-services files.
I guess that it is because the maven host is obtaining all the vars from the calling node.
I tried placing the var files under the same directory;
- group_vars/application1/application1
- group_vars/application1/application1-forms
- group_vars/application1/application1-services
In this case, all the vars are added to the groups, like if al var files were meshed in one single group file. In addition, variable names in application1-forms and application1-services should not be the same. In addition, I feel comfortable working with subgroups as this allow AWX to show the variables per subgroups instead as per group level.
Is there any way so the delegation can be achieved with all the variables defined with the original inventory structure?
Inventory structure:
- hostsfile [Contains hosts]
- group_vars/application1 [Contains application1 group vars]
- group_vars/application1-forms [Contains application1-forms group vars]
- group_vars/application1-services [Contains application1-servcices group vars]
Kind regards. David.