Hi,
I’m trying to create some sort of factory pattern I guess in my vars files for creating Amazon data pipeline jobs. What I want is to have a list of dicts, and each one will contain a parameter (“step”) that I want to be different per item. However, since this value is quite large & complicated, and will be used for 90% of the items, i don’t want to have to duplicate this value 40 or so times.
So, is it possible to include a vars file in another one? I tried using jinja2’s “include” function, but it complained that certain variables weren’t defined because it was trying to resolve the variables in the included file. In fact, those variables should be parsed later in the main play, now when including one vars file into the main one. I can’t use roles because this is part of a larger pattern in which the main vars file is loaded dynamically depending on another variable.
Some examples might make clear what I mean.
Here’s my playbook, “create-job.yml”:
- name: "Create a data pipeline and definition for {{ product }} {{ job }}"
hosts: localhost
gather_facts: True
vars_files:
- "vars/pipelines/{{ group }}/env/{{ env }}.yml"
- "vars/pipelines/{{ group }}/{{ job }}.yml"
Here’s my vars file, “job1.yml”, for the “job1” job:
template: multiple-emr
startTime: 03:00:00
definitions:
- product: web_v2
suite: websuite
{% include default_step.yml %} # how to include "default_step.yml"?
- product: db2
suite: dbsuite
{% include default_step.yml %}
- product: custom
suite: customsuite
{% include custom_step.yml %}
... x 40
And here’s the contents of “default_step.yml”:
s3_precondition: "/raw/data/#{node.myDate}/{{ product }}/"
step:
- "s3://my-bucket/artifacts/emr-jar-2.1.1.jar"
- "com.example.SampleEMR"
- "-Dinput=s3n://example-{{ env }}-data{{ s3_precondition | replace('node.', '') }}*{{ suite }}_#{myDate}.*.gz"
- "-Doutput=s3n://example-{{ env }}-data/intermediate/data/#{myDate}/{{ product }}/{{ suite }}/",
- "-DoutputFormat=json",
...
How can I achieve this with ansible?
Mark