Now that we have a basic development environment setup, we are going to explore how to create Ansible modules by taking a look at the obligatory Hello World Ansible module implementation. By creating a Hello World module, we can get our feet wet in Ansible module development and learn the basic structures required for a successful implementation. Let's get started!
To begin our Hello World module, let's create a directory structure that reflects the following screenshot:
Once this structure has been created, let's begin filling in our Ansible Hello World module code. To accomplish this, alter the helloworld.py
file to contain the following Python code:
#!/usr/bin/python # The following Python code converts a simple "Hello Ansible" message into a json object # for use with an Ansible module call import json message = "Hello Ansible" print(json.dumps({ "Message" : message }))
Once the preceding code has been implemented, we will want an efficient way to...