ansible / ansible.yang / 2.0.0 / lookup / spec This plugin reads the content of given yang document and generates json and xml configuration skeleton and a tree structure of yang document. Authors: Ganesh Nalawade (@ganeshrn)ansible.yang.spec (2.0.0) — lookup
Install with ansible-galaxy collection install ansible.yang:==2.0.0
collections: - name: ansible.yang version: 2.0.0
This plugin parses yang document and generates json and xml configuration skeleton and a tree structure of yang document. The tree structure document is as per RFC 8340 which helps to consume the yang document along with json and xml configuration skeleton.
- name: Get interface yang config spec without defaults set_fact: interfaces_spec: "{{ lookup('ansible.yang.spec', 'openconfig/public/release/models/interfaces/openconfig-interfaces.yang', search_path='openconfig/public/release/models:pyang/modules/', defaults=True, doctype='data') }}"
- name: Get interface yang spec with defaults and state data set_fact: interfaces_spec: "{{ lookup('ansible.yang.spec', 'openconfig/public/release/models/interfaces/openconfig-interfaces.yang', search_path='openconfig/public/release/models:pyang/modules/', defaults=True, doctype='data') }}"
_terms: description: The path points to the location of the top level yang module which is to be transformed into to Ansible spec. required: true type: str doctype: choices: - config - data default: config description: - Identifies the root node of the configuration skeleton. If value is C(config) only configuration data will be present in skeleton, if value is C(data) both config and state data fields will be present in output. type: bool defaults: default: false description: - This boolean flag indicates if the generated json and xml configuration schema should have fields initialized with default values or not. annotations: default: false description: - The boolean flag identifies if the xml skeleton should have comments describing the field or not. type: bool search_path: description: - is a colon C(:) separated list of directories to search for imported yang modules in the yang file mentioned in C(path) option. If the value is not given it will search in the same directory as that of C(yang_file). type: path keep_tmp_files: default: false description: - This is a boolean flag to indicate if the intermediate files generated while creating spec should be kept or deleted. If the value is C(true) the files will not be deleted else by default all the intermediate files will be deleted irrespective of whether task run is successful or not. The intermediate files are stored in path C(~/.ansible/tmp/yang/spec), this option is mainly used for debugging purpose. type: bool
_list: contains: json_skeleton: description: The json configuration skeleton generated from yang document returned: success sample: "{\n \"openconfig-interfaces:interfaces\": {\n \"interface\"\ : [\n {\n \"hold-time\": {\n \ \ \"config\": {\n \"down\": \"\",\n \ \ \"up\": \"\"\n }\n },\n \ \ \"config\": {\n \"description\": \"\",\n \ \ \"type\": \"\",\n \"enabled\": \"\",\n\ \ \"mtu\": \"\",\n \"loopback-mode\"\ : \"\",\n \"name\": \"\"\n },\n \ \ \"name\": \"\",\n \"subinterfaces\": {\n \ \ \"subinterface\": [\n {\n \ \ \"index\": \"\",\n \"config\":\ \ {\n \"index\": \"\",\n \ \ \"enabled\": \"\",\n \"description\"\ : \"\"\n }\n }\n \ \ ]\n }\n }\n ]\n }\n" type: dict tree: description: The tree representation of yang schema as per RFC 8340 returned: success sample: "module: openconfig-interfaces\n +--rw interfaces\n +--rw interface*\ \ [name]\n +--rw name -> ../config/name\n +--rw\ \ config\n | +--rw name? string\n | +--rw type\ \ identityref\n | +--rw mtu? uint16\n \ \ | +--rw loopback-mode? boolean\n | +--rw description? \ \ string\n | +--rw enabled? boolean\n +--ro state\n\ \ | +--ro name? string\n | +--ro type \ \ identityref\n | +--ro mtu? uint16\n | +--ro\ \ loopback-mode? boolean\n | +--ro description? string\n \ \ | +--ro enabled? boolean\n | +--ro ifindex? \ \ uint32\n | +--ro admin-status enumeration\n | +--ro\ \ oper-status enumeration\n | +--ro last-change? oc-types:timeticks64\n" type: dict xml_skeleton: description: The xml configuration skeleton generated from yang document returned: success sample: "<config xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n <interfaces\ \ xmlns=\"http://openconfig.net/yang/interfaces\">\n <interface>\n \ \ <name/>\n <config>\n <name/>\n <type/>\n <mtu/>\n\ \ <loopback-mode></loopback-mode>\n <description/>\n \ \ <enabled>True</enabled>\n </config>\n <hold-time>\n <config>\n\ \ <up></up>\n <down></down>\n </config>\n </hold-time>\n\ \ <subinterfaces>\n <subinterface>\n <index/>\n \ \ <config>\n <index></index>\n <description/>\n\ \ <enabled></enabled>\n </config>\n </subinterface>\n\ \ </subinterfaces>\n </interface>\n </interfaces>\n</config>\n" type: dict description: - It returns json skeleton configuration schema, xml skeleton schema and tree structure (as per RFC 8340) for given yang schema. type: raw