diff --git a/ansible_collections/arista/avd/plugins/action/eos_designs_structured_config.py b/ansible_collections/arista/avd/plugins/action/eos_designs_structured_config.py index 18a42f27815..b7e1f230775 100644 --- a/ansible_collections/arista/avd/plugins/action/eos_designs_structured_config.py +++ b/ansible_collections/arista/avd/plugins/action/eos_designs_structured_config.py @@ -44,14 +44,22 @@ def run(self, tmp: Any = None, task_vars: dict | None = None) -> dict: profiler = cProfile.Profile() profiler.enable() + hostname = task_vars["inventory_hostname"] + + if self._task.args.get("debug_vars") is True and (debug_vars_file := self._task.args.get("debug_vars_file")): + # Dump all hostvars to a file. + write_file(yaml.dump(task_vars["hostvars"][hostname], Dumper=AnsibleDumper, indent=2, sort_keys=False, width=2147483647), debug_vars_file) + + if self._task.args.get("structured_config") is False: + # Not creating structured config + return result + eos_designs_custom_templates = self._task.args.get("eos_designs_custom_templates", []) filename = str(self._task.args.get("dest", "")) file_mode = str(self._task.args.get("mode", "0o664")) template_output = self._task.args.get("template_output", False) validation_mode = self._task.args.get("validation_mode") - hostname = task_vars["inventory_hostname"] - task_vars["switch"] = get(task_vars, f"avd_switch_facts..{hostname}..switch", separator="..", default={}) # Read ansible variables and perform templating to support inline jinja2 diff --git a/ansible_collections/arista/avd/roles/eos_designs/tasks/main.yml b/ansible_collections/arista/avd/roles/eos_designs/tasks/main.yml index 389ef399d14..6a3d2e86726 100644 --- a/ansible_collections/arista/avd/roles/eos_designs/tasks/main.yml +++ b/ansible_collections/arista/avd/roles/eos_designs/tasks/main.yml @@ -34,23 +34,17 @@ check_mode: false run_once: true -- name: Generate YAML file with hostvars (only for debugging) - when: avd_eos_designs_debug | arista.avd.default(false) - ansible.builtin.template: - src: debug/generate-debug-vars.j2 - dest: "{{ structured_dir }}/{{ inventory_hostname }}-debug-vars.yml" - mode: "0o664" - delegate_to: localhost - changed_when: false - - name: Generate device configuration in structured format - when: avd_eos_designs_structured_config | arista.avd.default(true) + when: avd_eos_designs_structured_config | arista.avd.default(true) or avd_eos_designs_debug | arista.avd.default(false) arista.avd.eos_designs_structured_config: eos_designs_custom_templates: "{{ eos_designs_custom_templates | arista.avd.default([]) }}" dest: "{{ structured_dir }}/{{ inventory_hostname }}.{{ avd_structured_config_file_format }}" # cprofile_file: "structured-{{inventory_hostname}}.prof" template_output: true validation_mode: "{{ avd_data_validation_mode }}" + structured_config: "{{ avd_eos_designs_structured_config | arista.avd.default(true) }}" + debug_vars: "{{ avd_eos_designs_debug | arista.avd.default(false) }}" + debug_vars_file: "{{ structured_dir }}/{{ inventory_hostname }}-debug-vars.yml" delegate_to: localhost check_mode: false register: structured_config diff --git a/ansible_collections/arista/avd/roles/eos_designs/templates/debug/generate-debug-vars.j2 b/ansible_collections/arista/avd/roles/eos_designs/templates/debug/generate-debug-vars.j2 deleted file mode 100644 index 96ec042bb37..00000000000 --- a/ansible_collections/arista/avd/roles/eos_designs/templates/debug/generate-debug-vars.j2 +++ /dev/null @@ -1,6 +0,0 @@ -{# - Copyright (c) 2023-2024 Arista Networks, Inc. - Use of this source code is governed by the Apache License 2.0 - that can be found in the LICENSE file. -#} -{{ hostvars[inventory_hostname] | to_nice_yaml(indent=2, sort_keys=False, width=2147483647) }}