The second custom module

Building upon the last module, let's utilize the common module boilerplate from Ansible that's stated in the module development documentation (http://docs.ansible.com/ansible/dev_guide/developing_modules_general.html). We will modify the last custom module and create custom_module_2.py to ingest inputs from the playbook.

First, we will import the boilerplate code from ansible.module_utils.basic:

    from ansible.module_utils.basic import AnsibleModule        if __name__ == '__main__':        main()

From there, we can define the main function where we will house our code. AnsibleModule, which we have already imported, provides lots of common code for handling returns and parsing arguments. In the following example, we will parse three ...

Get Mastering Python Networking - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.