Skip to content

Commit

Permalink
Refactor(eos_designs): Move debug vars dump to action plugin instead …
Browse files Browse the repository at this point in the history
…of it's own task (#4540)
  • Loading branch information
ClausHolbechArista authored Oct 4, 2024
1 parent 863f2c9 commit a51a0d5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 4 additions & 10 deletions ansible_collections/arista/avd/roles/eos_designs/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

This file was deleted.

0 comments on commit a51a0d5

Please sign in to comment.