- Practical Ansible 2
- Daniel Oh James Freeman Fabio Alessandro Locati
- 671字
- 2021-06-24 16:06:47
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 both the Ansible control machine (as we covered earlier in this chapter) and on every managed node. Again, the exception here is Windows, which relies on PowerShell instead.
If you are working with operating system images that lack Python, the following commands provide a quick guide to getting Python installed:
- To install Python using yum (on older releases of Fedora and CentOS/RHEL 7 and below), use the following:
$ sudo yum -y install python
- On RHEL and CentOS version 8 and newer versions of Fedora, you would use the dnf package manager instead:
$ sudo dnf install python
You might also elect to install a specific version to suit your needs, as in this example:
$ sudo dnf install python37
- On Debian and Ubuntu systems, you would use the apt package manager to install Python, again specifying a version if required (the example given here is to install Python 3.6 and would work on Ubuntu 18.04):
$ sudo apt-get update
$ sudo apt-get install python3.6
The ping module we discussed earlier in this chapter for Ansible not only checks connectivity and authentication with your managed hosts, but it uses the managed hosts' Python environment to perform some basic host checks. As a result, it is a fantastic end-to-end test to give you confidence that your managed hosts are configured correctly as hosts, with the connectivity and authentication set up perfectly, but where Python is missing, it would return a failed result.
Of course, a perfect question at this stage would be: how can Ansible help if you roll out 100 cloud servers using a stripped-down base image without Python? Does that mean you have to manually go through all 100 nodes and install Python by hand before you can start automating?
Thankfully, Ansible has you covered even in this case, thanks to the raw module. This module is used to send raw shell commands to the managed nodes—and it works both with SSH-managed hosts and Windows PowerShell-managed hosts. As a result, you can use Ansible to install Python on a whole set of systems from which it is missing, or even run an entire shell script to bootstrap a managed node. Most importantly, the raw module is one of very few that does not require Python to be installed on the managed node, so it is perfect for our use case where we must roll out Python to enable further automation.
The following are some examples of tasks in an Ansible playbook that you might use to bootstrap a managed node and prepare it for Ansible management:
- name: Bootstrap a host without python2 installed raw: dnf install -y python2 python2-dnf libselinux-python - name: Run a command that uses non-posix shell-isms (in this example /bin/sh doesn't handle redirection and wildcards together but bash does) raw: cat < /tmp/*txt args: executable: /bin/bash - name: safely use templated variables. Always use quote filter to avoid injection issues. raw: "{{package_mgr|quote}} {{pkg_flags|quote}} install {{python|quote}}"
We have now covered the basics of setting up Ansible both on the control host and on the managed nodes, and we have given you a brief primer on configuring your first connections. Before we wrap up this chapter, we will look in more detail at how you might run the latest development version of Ansible, direct from GitHub.
- Splunk 7 Essentials(Third Edition)
- PowerShell 3.0 Advanced Administration Handbook
- Linux Mint System Administrator’s Beginner's Guide
- CorelDRAW X4中文版平面設計50例
- Apache Spark Deep Learning Cookbook
- Visual C++編程全能詞典
- Troubleshooting OpenVPN
- 基于單片機的嵌入式工程開發詳解
- Ruby on Rails敏捷開發最佳實踐
- TensorFlow Reinforcement Learning Quick Start Guide
- Unity Multiplayer Games
- PowerMill 2020五軸數控加工編程應用實例
- Machine Learning with Spark(Second Edition)
- Hands-On Business Intelligence with Qlik Sense
- 30天學通Java Web項目案例開發