---
- name: Test start msg for cli_config tests
  ansible.builtin.debug:
    msg: "START cli_config/nxos_template_file.yaml on connection={{ ansible_connection }}"

- name: Show what lookup will render
  ansible.builtin.debug:
    msg: "Rendered template: {{ lookup('ansible.builtin.template', 'basic/config_src_not_recommended.j2') }}"

- name: Setup - ensure loopback does not exist
  cisco.nxos.nxos_config:
    lines:
      - no interface Loopback998
  failed_when:
    - '"Invalid input detected" in result.stderr'

# These tests are influence of https://github.com/ansible-collections/ansible.netcommon/pull/743 PR
# with ansible-core 2,19+ the src attribute of config modules are impacted, the above mentioned PR
# adds backward compatibility to the src attribute to consider config files and also process jinja2 templates
# when mentioned. Also note that this backward compatibilty is added with a functionality deprecation
# as of January 2028, src would stop processing templates and only consider configuration files

- name: Apply configuration from file using inline lookup - must fail
  register: result
  cisco.nxos.nxos_config:
    src: "{{ lookup('ansible.builtin.template', 'basic/config_src_recommended.j2') }}"
  ignore_errors: true

- name: Apply configuration from file - not recommended tests backward compatibility
  register: result
  cisco.nxos.nxos_config:
    src: basic/config_src_not_recommended.j2

- name: Template a file - recommended way
  ansible.builtin.template:
    src: basic/config_src_recommended.j2
    dest: /tmp/config_src_recommended.j2
    mode: "0644"

- name: Apply configuration from file
  register: result
  cisco.nxos.nxos_config:
    src: /tmp/config_src_recommended.j2

- name: Asset step
  ansible.builtin.assert:
    that:
      - result.changed == true

- name: Cleanup - remove loopback interface
  cisco.nxos.nxos_config:
    lines:
      - no interface Loopback998
  failed_when:
    - '"Invalid input detected" in result.stderr'

- name: Test end msg for cli_config tests
  ansible.builtin.debug:
    msg: "END cli_config/nxos_template_file.yaml on connection={{ ansible_connection }}"
