pyang: YANG Model Validation and RFC 8340 Tree Generation
Short answer
A Pyang validates YANG modules and generates RFC 8340 tree diagrams with `-f tree`, operating on schema files rather than acting as a NETCONF client, Python automation framework, or Ansible module.
Question
Key Takeaways
pyang is a YANG model compiler and validator that checks module syntax, imports and semantic constraints, then renders RFC 8340 tree diagrams with the -f tree format. YANG model validation and tree diagram generation is the accurate role among the choices, because pyang processes schema files offline and never opens a NETCONF session, performs general Python automation, or runs as an Ansible module.
Expert Analysis
The decisive distinction is that pyang consumes schema files rather than live network sessions, so YANG validation and RFC 8340 tree generation is the only option consistent with the tool's actual input and output.
NETCONF client work begins only when persistent SSH RPC exchanges are required
A NETCONF client would displace pyang if the job were to open an SSH session to a Cisco IOS XE device, exchange <hello> capabilities, and carry <get-config> or <edit-config> operations inside NETCONF RPCs. That condition is absent: pyang is invoked against a .yang file and its imported modules, not a reachable management address, and it produces diagnostics and formatted schema text. ncclient is the library that owns the transport concerns—SSH subsystem negotiation, message-id tracking, RPC framing, and reply parsing—while pyang never establishes a session or sends an RPC. Validation can still be a prerequisite for a NETCONF workflow, because a module should parse cleanly before its payloads are trusted, but that ordering does not turn the validator into the client. If the task named a live device, a datastore, or a <get> operation, the NETCONF client condition would be met; the concrete artifact here is a model file and the expected product is an RFC 8340 tree, so the transport option fails at the input boundary on its own. A validator can run from a laptop with only the module search path; a client needs credentials, reachability and a NETCONF-capable server. Because no session, datastore, or RPC reply appears in the expected output, the transport framing has no work to do.
Schema-level checking of imports, augments and typedefs is what makes pyang fit
The controlling fact is that pyang works on the YANG schema itself: it resolves import and include statements, expands grouping/uses, follows typedef chains, validates augment targets and key definitions, and reports syntax or semantic faults before any configuration is rendered. That is exactly the activity named by YANG model validation, and -f tree adds a human-readable module tree in the notation standardized by RFC 8340. The output is not merely cosmetic: a tree exposes container hierarchy, list keys, config versus state flags, mandatory nodes, and choice/case branches, which is how a team reviews a model before constructing JSON or XML payloads. A tool that only printed a tree would be a formatter; pyang first builds a resolved schema graph and then renders it, so malformed imports or illegal augment paths are caught rather than drawn. This places pyang upstream of payload construction and device interaction. It fits the stated purpose because both halves—validation and RFC 8340 tree generation—are native outputs of the same model-processing run. The two outputs share one parse and one resolved schema, so they cannot drift apart. A tree generated after successful resolution is therefore evidence that the model's references are coherent. That makes the diagram a review artifact, not a substitute for validation.
Misreading Python automation, NETCONF transport and Ansible packaging breaks distinct roles
Option B costs the reader the distinction between an implementation language and a tool's function: pyang is written in Python, but labeling it Python automation says nothing about YANG validation and would equally describe Netmiko or ncclient scripts. Option C relocates schema checking into a runtime transport, so module errors would surface only after an SSH session and capability exchange, inverting the safe order of validating the model first. Option D invents a packaging relationship: an Ansible module is a Python unit invoked by a playbook task with Ansible-specific argument handling, whereas pyang is a standalone command-line validator and library, not a task plugin shipped for ansible-playbook. Each alternative also points to a different failure mode—B to vague scripting, C to connection and RPC errors, D to playbook integration errors—while the requested behavior is a deterministic check of a .yang file and an RFC 8340 rendering. None of those labels accounts for the -f tree output that makes the model reviewable. A reader choosing one of them would be unable to name the artifact pyang actually returns. The label also obscures that pyang's checks are model-specific, not host- or playbook-specific.
Validation output from pyang appears after module resolution and before payload construction
The effective step is the model-build phase, not runtime configuration. pyang parses the requested module, searches the include path supplied with -p for imports, constructs the schema tree, runs semantic checks, and only then emits the requested format; -f tree prints RFC 8340 notation after that resolution succeeds. In the tree, +--rw marks configuration data, +--ro marks state data, ? marks optional nodes, * marks lists, and [key] names a list key—symbols that let a reviewer spot mandatory or state-only nodes before writing a JSON or XML payload. A clean invocation exits successfully; diagnostics normally identify the file and line where an unresolved import, bad augment path, or type violation occurred. --lint adds style and common-error checks such as unused imports, while --strict enforces strict YANG compliance. Because unresolved imports or illegal augments stop reliable tree generation, this stage is the gate between model authoring and any RESTCONF or NETCONF payload work. The output can be redirected with -o for version control, so the tree becomes a reviewable artifact. No device connection or data model payload is involved at this point.
Official Reference
These links open the official vendor documentation in a new tab.
Exam Strategy
When a tool name appears alongside YANG, classify what it consumes and what it emits before matching the label. Schema-file inputs plus validation diagnostics or RFC 8340 tree output point to pyang; SSH sessions, <get-config>, and RPC replies point to ncclient or another NETCONF client. Verbs such as validate, compile, resolve imports, and render trees belong to model tooling, while connect, lock, edit-config, and get belong to runtime automation. Eliminate any choice that names a language or packaging format rather than the artifact the tool produces.
Related Analysis
Practice All 300-435 Questions
Access 150 questions with complete answers and detailed explanations.
View Full 300-435 Practice Test →