forked from PacktPublishing/Ansible-for-Real-life-Automation
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
49 changed files
with
304 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
# This is the documentation page for custom colletion demo | ||
|
||
(Documentation and detaiils goes here) | ||
|
||
This collection was created for Ansible Real Life book by Packt | ||
|
||
Author: [Gineesh Mada Pparambath](https://www.linkedin.com/in/gineesh/) | ||
|
||
Book Repository: [PacktPublishing/Ansible-for-Real-life-Automation](https://github.com/PacktPublishing/Ansible-for-Real-life-Automation/) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,11 @@ | ||
|
||
--- | ||
namespace: ginigangadharan | ||
name: custom_modules_demo | ||
version: 1.0.2 | ||
version: 1.0.4 | ||
readme: README.md | ||
authors: | ||
- Gineesh Madapparambath <[email protected]> | ||
description: Ansible Custom Module Demo | ||
description: Ansible Custom Module Demo for Ansible Book | ||
license: | ||
- GPL-2.0-or-later | ||
license_file: '' | ||
|
@@ -16,6 +15,6 @@ tags: | |
- devops | ||
dependencies: {} | ||
repository: https://github.com/PacktPublishing/Ansible-for-Real-life-Automation/ | ||
documentation: https://github.com/PacktPublishing/Ansible-for-Real-life-Automation/blob/main/Chapter-15/README.md | ||
homepage: https://github.com/PacktPublishing/Ansible-for-Real-life-Automation/blob/main/Chapter-15/README.md | ||
documentation: https://github.com/PacktPublishing/Ansible-for-Real-life-Automation/tree/main/Chapter-15/collection | ||
homepage: https://github.com/PacktPublishing/Ansible-for-Real-life-Automation/tree/main/Chapter-15/collection | ||
issues: https://github.com/PacktPublishing/Ansible-for-Real-life-Automation/issues |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
--- | ||
- name: Testing Custom Module | ||
hosts: node1 | ||
gather_facts: false | ||
|
||
vars: | ||
app_name: "bash" | ||
app_version: "1.0" | ||
|
||
tasks: | ||
- name: Application Name and Version | ||
customhello: | ||
application_name: "{{ app_name }}" | ||
application_version: "{{ app_version }}" | ||
register: custom_value | ||
|
||
- debug: | ||
msg: "{{ custom_value }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
--- | ||
- name: Testing Custom Module | ||
hosts: localhost | ||
gather_facts: false | ||
vars: | ||
custom_message: "Hello" | ||
custome_name: "John" | ||
tasks: | ||
- name: Calling custom module | ||
hello_message: | ||
message: "{{ custom_message }}" | ||
name: "{{ custome_name }}" | ||
register: custom_value | ||
|
||
- debug: | ||
msg: "{{ custom_value }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/bin/bash | ||
# | ||
# This script accepts two inputs | ||
# 1. application_name | ||
# 2. application_version | ||
|
||
changed="false" | ||
display="This is a simple bash module" | ||
OS="$(uname)" | ||
HOSTNAME="$(uname -n)" | ||
|
||
source $1 | ||
display="Application Name: $application_name (version: $application_version)" | ||
if [ "$application_name" == "bash" ]; then | ||
changed="true" | ||
display="$display - This is a bash App" | ||
fi | ||
|
||
printf '{"changed": %s, "msg": "%s", "operating_system": "%s", "hostname": "%s"}' "$changed" "$display" "$OS" "$HOSTNAME" | ||
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
#!/usr/bin/python | ||
# -*- coding: utf-8 -*- | ||
|
||
# NO Copyright: feel freee to use - Gineesh ([email protected]) | ||
|
||
|
||
DOCUMENTATION = ''' | ||
--- | ||
module: hello_message | ||
short_description: A Hello Message Module | ||
version_added: "2.10" | ||
description: | ||
- "A Hello Message Module" | ||
options: | ||
message: | ||
description: | ||
- The message to be printed. | ||
required: true | ||
type: string | ||
name: | ||
description: | ||
- The name of the person. | ||
required: false | ||
type: string | ||
author: | ||
- Gineesh Madapparambath (@ginigangadharan) | ||
''' | ||
|
||
EXAMPLES = ''' | ||
# Simple Custom Hello App | ||
- name: Calling hello_message module | ||
hello_message: | ||
message: "Hello" | ||
name: "John" | ||
''' | ||
|
||
RETURN = ''' | ||
greeting: | ||
description: Hello Response | ||
returned: success | ||
type: str | ||
sample: Hello World | ||
os_version: | ||
description: Operating System Information | ||
returned: success | ||
type: str | ||
sample: Linux 4.18.0-305.el8.x86_64 #1 SMP Thu Apr 29 08:54:30 EDT 2021 | ||
''' | ||
|
||
from ansible.module_utils.basic import AnsibleModule, platform | ||
|
||
def main(): | ||
module_args = dict( | ||
message=dict(type='str', required=True), | ||
name=dict(type='str', required=False), | ||
) | ||
result = dict( | ||
changed=False, | ||
greeting='Sample Message', | ||
os_version='' | ||
) | ||
module = AnsibleModule( | ||
argument_spec=module_args, | ||
supports_check_mode=True | ||
) | ||
|
||
# if check mode | ||
if module.check_mode: | ||
module.exit_json(**result) | ||
|
||
# default name | ||
source_name = "World" | ||
|
||
# if message is fail, then fail | ||
if module.params['message'] == 'fail': | ||
module.fail_json(msg='Failing this module', **result) | ||
|
||
if module.params['name']: | ||
source_name = module.params['name'] | ||
|
||
result['greeting'] = module.params['message'] + " " + source_name | ||
result['os_version'] = platform.system()+ " " + platform.release() + " " + platform.version() | ||
module.exit_json(**result) | ||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+164 KB
images/Figure 15.1. Playbook to install and verify Python using raw module. .png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+42.2 KB
images/Figure 15.20. Jinja2 template to prepare Akamai API call body .png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+132 KB
images/Figure 15.26. Ansible playbook with customhello module task (1).png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+146 KB
images/Figure 15.32. Custom module details using ansible-doc command.png
Oops, something went wrong.
Binary file added
BIN
+135 KB
...5.33. Ansible custom module documentation details using ansible-doc command.png
Oops, something went wrong.
Oops, something went wrong.
Binary file added
BIN
+95 KB
images/Figure 15.35. Verify playbook execution and hello_message module.png
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Binary file added
BIN
+67.2 KB
images/Figure 15.5. FortiOS backup using fortios_monitor_fact module..png
Oops, something went wrong.
Oops, something went wrong.
Binary file added
BIN
+117 KB
images/Figure 15.7. Inventory variables for FortiOS connection without httpapi.png
Oops, something went wrong.
Binary file added
BIN
+60.8 KB
images/Figure 15.8. Running FortiOS software upgrade using raw module.png
Oops, something went wrong.
Oops, something went wrong.