200-901 exam dumps

200-901 practice question 23 of 204

Cisco DevNet Associate. Associate level, Cisco. Free question with the correct answer and a full explanation.

200-901 Question 23

Select 2

A DevOps engineer is tasked with updating a network automation script to dynamically add or remove devices from a network inventory stored in a custom YAML file. The script must ensure the changes are reflected correctly without overwriting existing data. Which Python modules and methods would be most appropriate for this task?

  1. A

    Use the yaml module to parse and modify the YAML file.

  2. B

    Use the json module to convert the YAML file into JSON for easier manipulation.

  3. C

    Use the open() function in write ('w') mode to rewrite the entire YAML file after making changes.

  4. D

    Use the append() method to directly add new devices to the YAML file.

  5. E

    Use the ruamel.yaml library for preserving the structure and comments of the YAML file.

Show answer and explanation

Correct answers: A, E

Explanation

To dynamically add or remove devices from a YAML-based inventory file, it is important to use libraries and methods tailored for YAML file manipulation. The yaml module allows for parsing and modifying YAML content, while the ruamel.yaml library goes a step further by preserving the file's structure, formatting, and comments, ensuring that updates do not disrupt the integrity of the file. Overwriting the file or using inappropriate methods, such as handling YAML as JSON, can lead to data loss or corruption.

  • A. Correct.

    Correct: The yaml module provides tools to parse and modify YAML files directly, making it a suitable choice for reading and updating the network inventory.

  • B. Incorrect.

    Incorrect: While the json module is useful for handling JSON data, YAML is a different format and requires a dedicated library for proper handling.

  • C. Incorrect.

    Incorrect: Using open() in write ('w') mode will overwrite the entire file, which does not align with the requirement to preserve existing data.

  • D. Incorrect.

    Incorrect: The append() method does not directly apply to file manipulation in Python. It is commonly used for lists, not for appending data directly to files.

  • E. Correct.

    Correct: The ruamel.yaml library is specifically designed for YAML file manipulation and is capable of preserving the structure, formatting, and comments, making it ideal for dynamically adding or removing devices.

Timed practice exam

Take a 200-901 practice test under exam conditions

75 questions in 120 minutes, drawn from this bank, with a score report and a per-question review when you finish.

Start timed exam