Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Ansible for Real-Life Automation

You're reading from  Ansible for Real-Life Automation

Product type Book
Published in Sep 2022
Publisher Packt
ISBN-13 9781803235417
Pages 480 pages
Edition 1st Edition
Languages
Concepts
Author (1):
Gineesh Madapparambath Gineesh Madapparambath
Profile icon Gineesh Madapparambath

Table of Contents (22) Chapters

Preface 1. Part 1: Using Ansible as Your Automation Tool
2. Chapter 1: Ansible Automation – Introduction 3. Chapter 2: Starting with Simple Automation 4. Chapter 3: Automating Your Daily Jobs 5. Chapter 4: Exploring Collaboration in Automation Development 6. Part 2: Finding Use Cases and Integrations
7. Chapter 5: Expanding Your Automation Landscape 8. Chapter 6: Automating Microsoft Windows and Network Devices 9. Chapter 7: Managing Your Virtualization and Cloud Platforms 10. Chapter 8: Helping the Database Team with Automation 11. Chapter 9: Implementing Automation in a DevOps Workflow 12. Chapter 10: Managing Containers Using Ansible 13. Chapter 11: Managing Kubernetes Using Ansible 14. Chapter 12: Integrating Ansible with Your Tools 15. Chapter 13: Using Ansible for Secret Management 16. Part 3: Managing Your Automation Development Flow with Best Practices
17. Chapter 14: Keeping Automation Simple and Efficient 18. Chapter 15: Automating Non-Standard Platforms and Operations 19. Chapter 16: Ansible Automation Best Practices for Production 20. Index 21. Other Books You May Enjoy

Automating Non-Standard Platforms and Operations

So far, you have learned about the different systems and platforms (managed nodes) such as Linux systems, Microsoft Windows systems, network devices, and cloud platforms, all of which can be automated using Ansible. You have used different methods and protocols to connect to the target system or platform to execute the automated operations. You do not need to understand how complex operations are running inside these systems because Ansible will understand and take appropriate actions on the target systems to reach the desired state.

What if there are no standard Ansible modules or connection methods available for a specific operation on the managed node? Or what if the module is missing some feature you are looking for? For example, let’s say you want to automate a machine that doesn’t have the supported Python version installed, and you want to use Ansible to automate this Python installation or run raw commands on...

Technical requirements

You will need the following technical requirements for this chapter:

  • A Linux machine for the Ansible control node
  • Basic knowledge of commands for network devices (for example, FortiOS and Cisco ASA)
  • Basic knowledge of REST API endpoints and their usages
  • Basic knowledge of bash scripting and the Python programming language

All the Ansible artifacts, commands, and snippets for this chapter can be found in this book’s GitHub repository at https://github.com/PacktPublishing/Ansible-for-Real-life-Automation/tree/main/Chapter-15.

Executing low-down raw commands

So far, you have learned about different Ansible modules and collections for developing automation content. Most of these modules expect a supported Python version on the target node (or PowerShell for Microsoft Windows) to execute the automation scripts in the backend (refer to Ansible’s managed node requirements documentation for more details: https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html#managed-node-requirements). When there is no required Python version or packages available, then you need to install it manually (or using some scripts) on every node before Ansible can automate the tasks on that nodes. When several managed nodes need to onboard to Ansible, then it will be a tedious task to log into each node and install these dependencies manually. In such situations, it is possible to execute the raw commands (such as the ones you use inside a bash script or PowerShell script) to install and configure...

Using raw commands for network operations

Ansible has a large collection of modules and plugins to support most of the well-known network and firewall devices. The following figure shows some of the supported network devices and brands for network automation:

Figure 15.3 – Supported brands for Ansible network automation (source: https://www.ansible.com/integrations/networks)

However, there will be situations where you must overcome the following challenges:

  • No supported Ansible module is available to execute a specific network or firewall operation.
  • There is a module available for operation but the specific feature or parameter you are looking for doesn’t exist in the current module version.
  • The supported module for the operation is using a slow method compared to the CLI command on the device.

Network Collections in the Ansible Collection Index

Refer to the documentation page at https://docs.ansible.com/ansible/latest...

Using API calls for automation

In Chapter 6, Automating Microsoft Windows and Network Devices, you learned about the different ways Ansible can talk to managed nodes, platforms, or applications. So as long as there is a supported method to access the target system, it is possible use Ansible to automate these tasks. In the previous chapters, you learned about the integration between Ansible and other tools such as Jira, ServiceNow, Kubernetes, public or private cloud platforms, and so on. For such platforms, most of those modules use HTTP/HTTPS API calls to execute operations. This means that if there are no modules available to automate your operations but there is an API method, you can use the same raw API calls from your Ansible playbook.

Python SDK and API Calls

Please remember that not all modules use direct or native API calls to execute the operations; some modules use Python libraries and software development kits (SDKs) to implement these tasks. For example, the FortiOS...

Creating custom modules for Ansible

In the previous sections, you learned how to automate operations if the standard modules are not available for specific tasks. But modules are the standard way of implementing automation and help you develop Ansible playbooks without worrying about the complex operations in the backend. If you know the backend operations and how to execute the tasks in the backend, then create a module for Ansible to execute a specific operation. Finally, contribute it back to the community via Ansible collections. That is the way the open source community grows.

Facts to check before creating a custom Ansible module

You can use any programming language (which can be called by the Ansible API, the ansible command, or the ansible-playbook command), libraries, and methods for your new Ansible module. Most of the Ansible modules that you are using now are written in the Python programming language. Before developing a new module, check yourself on the following...

Summary

In this chapter, you learned how to use Ansible to automate non-supported and non-standard operations using the Ansible raw module. You explored the raw command’s execution on servers, network devices, firewall devices, and more.

Then, you learned how to interact with the devices that provide API-based operations. The Ansible uri module was used to interact with a ToDo application; you explored the options for fetching and adding items to the application via APIs. You also learned about the API-based operations for devices and explored some sample usage using the Akamai DNS API.

In addition to the raw command and API-based operations, you learned about Ansible custom modules and how to create custom modules using bash and Python. In the end, you distributed the custom modules to Ansible Galaxy as an Ansible content collection.

With that, you have explored a common production use case where you can use Ansible as a perfect automation tool and Red Hat Ansible...

Further reading

To learn more about the topics that were covered in this chapter, take a look at the following resources:

lock icon The rest of the chapter is locked
You have been reading a chapter from
Ansible for Real-Life Automation
Published in: Sep 2022 Publisher: Packt ISBN-13: 9781803235417
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at ₹800/month. Cancel anytime}