The first version of Ansible was released in 2012. The software combines configuration management, automated command execution, and software distribution. Tasks are defined with scripts, which Ansible then executes on the desired systems. These capabilities are in demand in the administration and management of IT systems. Originally designed for Unix operating systems, Ansible has also been compatible with Windows through PowerShell since version 1.7. The developers of Ansible defined four clear goals above all. The tool is meant to meet the following requirements.
- easy to learn
- particularly secure
- reliable
- limited to a minimal scope
In Which Scenarios Is Ansible Used?
Ansible is used primarily in the administration of IT landscapes. The size or form of the IT infrastructure is not decisive. A small local network consisting of a few workstations and a server can be managed just as effectively as a large network with its own intranet.
The following prerequisites are necessary to use Ansible.
- A server or a workstation with Linux. As a rule, a central server is chosen that the IT administrators can access at any time.
- A company network. Orchestration is carried out over the network. Ansible is compatible with the public internet as well as with intranets, local networks, and VPNs.
- An SSH connection. All communication within the network runs over Secure Shell. SSH connections with certificates must be possible for this.
Advantages of Ansible
There are many reasons in favor of Ansible in practice. First of all, it is an open source application. The source code is open, which simplifies adaptation, and you are free to choose an IT service provider as a partner. Ansible is also very easy to introduce. For one thing, it has no dependencies on other programs or extra libraries. Ansible does not need a database to operate either. For another, it requires no installation on the client systems. The modules can be stored on any computer in the network. All systems that you want to control remotely with Ansible only need access via SSH. A terminal application of your choice gives you this access. All configurations can be edited with a simple text editor. The actions are stored centrally and called from there. Execution then takes place remotely through the SSH access. This makes it easy to add systems to the Ansible network and to access the configurations.
Ansible in Practice
Ansible can address a large number of systems. First, the systems to be managed have to be made known to the central Ansible database. Ansible uses an INI file for this. That makes it easy to add new systems and to keep an overview. Every system can be identified easily. An example INI file looks as follows.
www1.beispiel.de
www2.beispiel.de
[datenbankserver]
db0.beispiel.de
db1.beispiel.de
How Ansible Is Configured
The actual configurations in Ansible are called “playbooks.” These playbooks hold configurations as well as commands for deployment and orchestration. In principle, they are individual scripts that Ansible then executes on the target machines over the network. The playbooks are written in YAML, which makes it easier to get started with the system. Ansible can carry out very different tasks in the configuration and orchestration of IT systems. For example, it is possible to check all or some of the workstations in the network for current software packages. These commands are also stored in a playbook. If, for example, you want to keep httpd up to date at all times, a playbook can look as follows.
tasks:
- name: Make sure Apache is up to date
yum: pkg=httpd state=latest
The entry “hosts” defines the systems that are to be addressed. All clients, only certain workstations, or groups can be named here. The list of tasks then follows under “tasks.” You can list several tasks here, which are then processed in the corresponding order. You can use the line “name” freely. It serves to describe the command executed in the following line, which keeps the playbook readable.
With Ansible, you can also check services on systems in the network. This lets you verify remotely whether the desired services are available. In the same way, you can start, stop, or restart services. If, for example, you want to check whether the httpd daemon is active, the following command is added to the playbook.
service: name=httpd state=started enabled=yes
In addition, tags can be set in the playbooks. This helps to keep an overview, above all in larger playbooks. Tags can also be used to define groups of systems. Different areas of responsibility can be described with tags in this way, for instance “pakete” (packages) and “config.” A corresponding playbook could look as follows.
- yum:
name: "{{ item }}"
state: installed
loop:
- httpd
- memcached
tags:
- pakete
- template:
src: templates/src.j2
dest: /etc/foo.conf
tags:
- config
A further advantage is that you can download preconfigured playbooks. They cover a wide range of tasks. You do not have to write complete installation routines yourself, for example, and can use a standard playbook for this task. That saves time in administration.
Working with Ansible
If you want to execute the commands stored in a playbook, proceed as follows. Open an SSH connection and run the corresponding playbook from the command line. Let us assume that you have stored a task with the name “beispiel.yml.” The command line then looks as follows.
ansible-playbook beispiel.ymlIt is also possible to call the corresponding playbook from the command line and to execute only certain commands. A command line that executes all commands with the tag “config” but ignores commands with the tag “pakete” could look like this.
ansible-playbook beispiel.yml --tags "config" --skip-tags "pakete"This shows a fundamental strength of Ansible. Because the systems to be addressed are stored in the playbook and defined through the host file, the commands can in principle be called from any system in the network. Ansible executes the tasks automatically on the correct machines, provided that they can be reached over the network.
Conclusion on Ansible as a Strong Tool for IT Administrators
Ansible brings the capabilities that a program for orchestration over the network needs. It allows administrators to create their own libraries of scripts and to run them on the machines in the network. It leaves a great deal of freedom in how you set this up, and groups and tags let you filter out specific clients at any time. Existing playbooks make for a quick start and give even beginners the opportunity to understand and use the functions of Ansible. Ansible is lightweight and flexible and has proven itself as a pragmatic tool for orchestrating small and large infrastructures alike.