Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Practical Ansible - Second Edition

You're reading from  Practical Ansible - Second Edition

Product type Book
Published in Sep 2023
Publisher Packt
ISBN-13 9781805129974
Pages 420 pages
Edition 2nd Edition
Languages
Authors (3):
James Freeman James Freeman
Profile icon James Freeman
Fabio Alessandro Locati Fabio Alessandro Locati
Profile icon Fabio Alessandro Locati
Daniel Oh Daniel Oh
Profile icon Daniel Oh
View More author details

Table of Contents (21) Chapters

Preface 1. Part 1:Learning the Fundamentals of Ansible
2. Chapter 1: Getting Started with Ansible 3. Chapter 2: Understanding the Fundamentals of Ansible 4. Chapter 3: Defining Your Inventory 5. Chapter 4: Playbooks and Roles 6. Part 2:Expanding the Capabilities of Ansible
7. Chapter 5: Creating and Consuming Modules 8. Chapter 6: Creating and Consuming Collections 9. Chapter 7: Creating and Consuming Plugins 10. Chapter 8: Coding Best Practices 11. Chapter 9: Advanced Ansible Topics 12. Part 3:Using Ansible in an Enterprise
13. Chapter 10: Network Automation with Ansible 14. Chapter 11: Container and Cloud Management 15. Chapter 12: Troubleshooting and Testing Strategies 16. Chapter 13: Getting Started with Ansible Automation Controller 17. Chapter 14: Execution Environments 18. Assessments 19. Index 20. Other Books You May Enjoy

Getting Started with Ansible

Ansible enables you to easily deploy applications and systems consistently and repeatably using native communication protocols such as SSH and WinRM. As a result, Ansible is agentless and so requires nothing to be installed on the managed systems (except for Python, which, these days, is present on most systems). As a result, it enables you to build a simple yet robust automation platform for your environment.

Ansible is straightforward to install and also comes packaged for many modern systems. Its architecture is serverless as well as agentless, so it has a minimal footprint. You can choose to run it from a central server or your own laptop—the choice is entirely yours. You can manage anything from a single host to hundreds of thousands of remote hosts from one Ansible control machine. All remote machines can be managed by Ansible, and with sufficient playbooks created, you may never have to log in to any of these machines individually again...

Technical requirements

Ansible has a fairly minimal set of system requirements—as such, you should find that if you have a machine (either a laptop, a server, or a virtual machine (VM)) that is capable of running Python, then you will be able to run Ansible on it. Later in this chapter, we will demonstrate the installation methods for Ansible on a variety of operating systems—it is hence left to you to decide which operating systems are right for you.

The one exception to the preceding statement is Microsoft Windows—although there are Python environments available for Windows, there is as yet no native build of Ansible for Windows. Readers running more recent versions of Windows will be able to install Ansible using Windows Subsystem for Linux (henceforth, WSL) by following the procedures outlined later for their chosen WSL environment (for example, if you install Ubuntu on WSL, you should simply follow the instructions given in this chapter for installing Ansible...

Installing and configuring Ansible

Ansible is written in Python and, as such, can be run on a wide range of systems. This includes the most popular flavors of Linux, FreeBSD, and macOS. The one exception to this is Windows, where though native Python distributions exist, there is as yet no native Ansible build. As a result, your best option at the time of writing is to install Ansible under WSL, proceeding as if you were running on a native Linux host.

Once you have established the system on which you wish to run Ansible, the installation process is normally simple. In the following sections, we will discuss how to install Ansible on a wide range of different systems so that most readers should be able to get up and running with Ansible in a matter of minutes.

Understanding Ansible version numbers

When the previous edition of this book was published, Ansible followed a relatively simple version numbering scheme. All releases of Ansible included all the modules, plugins, and...

Getting to know your Ansible installation

By this stage in this chapter, regardless of your choice of operating system for your Ansible control machine, you should have a working installation of Ansible with which to begin exploring the world of automation. In this section, we will carry out a practical exploration of the fundamentals of Ansible to help you to understand how to work with it. Once you have mastered these basic skills, you will then have the knowledge required to get the most out of the remainder of this book. Let’s get started with an overview of how Ansible connects to non-Windows hosts.

Understanding how Ansible connects to hosts

With the exception of Windows hosts (as discussed at the end of the previous section), Ansible uses the SSH protocol to communicate with hosts. The reasons for this choice in the Ansible design are many, not least that just about every Linux/FreeBSD/macOS host has it built in, as do many network devices such as switches and routers...

Managed node requirements

So far, we have focused almost exclusively on the requirements for the Ansible control host and have assumed that (except for the distribution of the SSH keys) the target hosts will just work. This, of course, is not always the case, and for example, while a modern installation of Linux installed from an ISO will often just work, cloud operating system images are often stripped down to keep them small, and so might lack important packages such as Python, without which Ansible cannot operate.

If your target hosts are lacking Python, it is usually easy to install it through your operating system’s package management system. Ansible requires you to install either Python version 2.7 or 3.5 (and above) on the Ansible-managed nodes but has more stringent requirements for the control node. At the time of writing, ansible-core 2.15 (which accompanies Ansible 8.0.0) requires a version of Python between 3.9 and 3.11 to be installed on the control node. This...

Summary

Ansible is a powerful and versatile yet simple automation tool, of which the key benefits are its agentless architecture and its simple installation process. Ansible was designed to get you from zero to automation rapidly and with minimal effort, and we have demonstrated the simplicity with which you can get up and running with Ansible in this chapter.

In this chapter, you learned the basics of setting up Ansible—how to install it to control other hosts, and the requirements for nodes being managed by Ansible. You learned about the fundamentals required to set up SSH and WinRM for Ansible automation, as well as how to bootstrap managed nodes to ensure they are suitable for Ansible automation. You also learned about ad hoc commands and their benefits. Finally, you learned how to run the latest version of the code directly from GitHub, which both enables you to contribute directly to the development of Ansible and gives you access to the very latest features should...

Questions

  1. On which operating systems can you set up an Ansible control node? (There are multiple correct answers.)
    1. Ubuntu 22.04
    2. Fedora 35
    3. Windows Server 2022
    4. HP-UX
    5. Mainframe
  2. Which protocol does Ansible use to connect to non-Windows managed nodes for running tasks?
    1. HTTP
    2. HTTPS
    3. SSH
    4. TCP
    5. UDP
  3. To execute a specific module in the Ansible ad hoc command line, you need to use the -m option.
    1. True
    2. False

Further reading

  • For any questions about installation via Ansible’s mailing list on Google Groups, refer to the following URL:

https://groups.google.com/forum/#!forum/ansible-project

  • Information on how to install the latest version of pip can be found here:

https://pip.pypa.io/en/stable/installation/

  • Details of specific Windows modules using PowerShell can be found here:

https://docs.ansible.com/ansible/latest/collections/ansible/windows/index.html

  • If you have a GitHub account and want to follow the GitHub project, you can keep tracking issues, bugs, and ideas for Ansible at the following URL:

https://github.com/ansible/ansible

lock icon The rest of the chapter is locked
You have been reading a chapter from
Practical Ansible - Second Edition
Published in: Sep 2023 Publisher: Packt ISBN-13: 9781805129974
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 €14.99/month. Cancel anytime}