Skip to content

Conversation

@anisf
Copy link
Contributor

@anisf anisf commented Sep 14, 2022

Allows to use variables in definition_file, e.g. :

clusters:

- name: "{{ cdp_cluster_name }}"
  type: base
  services: "{{ cdp_services }}"
  databases: "{{ cdp_databases }}"
  configs: "{{ fresh_install_configs }}"
  host_templates: "{{ cdp_host_templates }}"
...

@anisf anisf marked this pull request as ready for review September 14, 2022 11:03
@Chaffelson
Copy link
Contributor

Chaffelson commented Sep 14, 2022

So there is a reason for this, and it is a trade off.
The definition.yml is loaded with variable evaluation, but the cluster.yml is not, so that those variables are evaluated later in the process. The initial import of the cluster template is just to import information like the repositories, however for many cluster templates it's necessary to evaluate the template once the rest of the services are built so you can pick up things like hostnames and service names which don't exist until that point of the process.
This isn't ideal for templating parts of the cluster definition as you are doing, so there may be a better way to do it that can be found, but importing cluster.yml with variables evaluated at the start of the deployment would break in those late-evaluation use-cases, so this was the compromise in the name of backwards compatibility.

@anisf
Copy link
Contributor Author

anisf commented Sep 14, 2022

Just to be clear, the variable _pre_template_cluster is only used to do the following check :

- name: Find the correct host template
  block:
  - fail:
      msg: "Unable to host template {{ host_template }} in the cluster definition"
    when: content | length == 0
  - set_fact:
      host_template_content: "{{ content | first }}"
  vars:
    query: "clusters[].host_templates[].\"{{ host_template }}\""
    content: "{{ _pre_template_cluster | json_query(query) }}"
  when: host_template is defined

You can do a search on all cloudera-labs repositories to find the modified variable here

This PR does not touch to any other variable that _pre_template_cluster

The include_vars task in this PR is stored under the _pre_template_cluster variable. Just like the replace lookup actually does :

- name: Load Definition file
  ansible.builtin.include_vars:
    file: "{{ init__cluster_definition_file }}"
    name: _pre_template_cluster
...

And if you take a look at the distribute_facts_to_inventory.yml file a few lines after, you'll see almost the same task, but this time, loading variables directly instead of under a variable :

- name: Include Cluster Definition override
  ansible.builtin.include_vars:
    file: "{{ init__cluster_definition_file }}"
  delegate_to: "{{ __play_host }}"
  delegate_facts: true
  loop: "{{ groups.all }}"
  loop_control:
    loop_var: __play_host
    label : __play_host

Notice the name parameter for the include_vars is not present in this task

@Chaffelson Chaffelson requested a review from wmudge November 10, 2022 12:51
@Chaffelson Chaffelson merged commit 18b4bfa into cloudera-labs:devel Nov 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants