Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ansible.netcommon.restconf_get: Option to allow not existing instances #500

Open
netgab opened this issue Jan 10, 2023 · 0 comments
Open

Comments

@netgab
Copy link

netgab commented Jan 10, 2023

SUMMARY

When ansible.netcommon.restconf_get is used to retrieve not existing data, the RESTCONF server sends an HTTP 404 error and the corresponding Ansible task fails. As a consequence processing of subsequent task for the given host stops.

Especially when performing queries (GET requests), it may be sane that a resource does not exists. Imagine there is a playbook with multiple tasks querying different RESTCONF resources, to report the precense (or absence) or certain configuration.

ISSUE TYPE
  • Feature Idea
COMPONENT NAME

ansible.netcommon.restconf_get

ADDITIONAL INFORMATION

The RESTCONF RFC states the following regarding not-existing resources:

   If a retrieval request for a data resource represents an instance
   that does not exist, then an error response containing a "404 Not
   Found" status-line MUST be returned by the server.  The error-tag
   value "invalid-value" is used in this case.

It is proposed, that a new attribute is added to ansible.netcommon.restconf_get:

  • Parameter: ignore_not_exist_resource (boolean) / Default: false

When the parameter is set to true, Ansible does not consider the task failed, when:
code==404 and error-tag == 'invalid-value'

This is an example for a verbose task output:

TASK [RESTCONF: Get interface (1)] *************************************************************************************************************************************************************************************************************************************************
ok: [device1] => {"changed": false, "failed_when_result": false, "response": {"Cisco-IOS-XE-native:Loopback": [{"logging": {"event": {"link-status-enable": false}}, "name": 900}]}}
ok: [device2] => {"changed": false, "code": 404, "failed_when_result": false, "msg": "{'ietf-restconf:errors': {'error': [{'error-type': 'application', 'error-tag': 'invalid-value', 'error-message': 'uri keypath not found'}]}}"}

The task for device2 succeeds, although the resource has not been found.

I simulated this with the following failed_when statement:

  tasks:
    - name: "RESTCONF: Get interface (1)"
      ansible.netcommon.restconf_get:
        path: "/Cisco-IOS-XE-native:native/interface/Loopback=900"
      register: restconf_result
      failed_when:
        - restconf_result.response is not defined
        - restconf_result.code != 404
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant