---
- name: Get facts
  hosts: all
  connection: local                       # code is run locally
  gather_facts: no                        # don't gather facts
  tasks:
    - block:
        - name: get facts from device
          napalm_get_facts:                   # NAPALM plugin
            provider: {}
            hostname: "{{ host }}"            # start of connection parameters
            username: "{{ user }}"
            dev_os: "{{ os }}"
            password: "{{ password }}"
            optional_args:
                path: "{{ playbook_dir }}/mocked/{{ inventory_hostname }}"
                profile: "{{ profile }}"
            filter: ['facts', 'route_to', 'interfaces']                # which NAPALM getters to use
            args:
                route_to:
                    protocol: static
                    destination: 8.8.8.8
          register: test_napalm             # store information here
        - assert:
            that:
                - test_napalm.ansible_facts.napalm_facts.hostname == "localhost"
                - test_napalm.ansible_facts.napalm_interfaces.Ethernet1.mac_address == "08:00:27:C6:00:F0"
      rescue:
        - debug:
                var: ansible_failed_result.msg
        - assert:
            that:
                - "{{ '[interfaces] cannot retrieve device data' in ansible_failed_result.msg }}"
                - "{{ 'Key blah is not present' in ansible_failed_result.msg }}"

---
- name: Get facts
  hosts: all
  connection: local                       # code is run locally
  gather_facts: no                        # don't gather facts
  tasks:
    - block:
        - name: get facts from device
          napalm_get_facts:                   # NAPALM plugin
            hostname: "{{ host }}"            # start of connection parameters
            username: "{{ user }}"
            dev_os: "{{ os }}"
            password: "{{ password }}"
            optional_args:
                path: "{{ playbook_dir }}/mocked/{{ inventory_hostname }}"
                profile: "{{ profile }}"
            filter: ['facts', 'route_to', 'interfaces']                # which NAPALM getters to use
            args:
                route_to:
                    protocol: static
                    destination: 8.8.8.8
          register: test_napalm             # store information here
        - assert:
            that:
                - test_napalm.ansible_facts.napalm_facts.hostname == "localhost"
                - test_napalm.ansible_facts.napalm_interfaces.Ethernet1.mac_address == "08:00:27:C6:00:F0"
      rescue:
        - debug:
                var: ansible_failed_result.msg
        - assert:
            that:
                - "{{ '[interfaces] cannot retrieve device data' in ansible_failed_result.msg }}"
                - "{{ 'Key blah is not present' in ansible_failed_result.msg }}"

Remove unintended provider change in tests
Remove unintended provider change in tests
