Learn Ansible: An open source automation tool for applications and IT infrastructure
Questions and answers
What does Ansible Playbook mean?
"Ansible German - Ansible is an open source orchestration tool. An Ansible playbook is an organized unit of scripts. With Ansible, a master server can configure a slave server - the master connects to the "slave" via SSH and executes predefined tasks. Each Ansible task describes a configuration step, such as installing a package using Ansible Yum. Each task calls a module in the form of Ansible modules that implements the current task (e.g. the yum module). The copy module is used when a file is to be copied. The Ansible systemd module can be used to manage Ansible systemd services. Ansible version 2.7 comes with around 2,100 Ansible modules. Additional modules can also be easily imported. If you want to combine several Ansible tasks, you can use an Ansible Playbook. Ansible Playbook defines server configurations that are managed by the Ansible automation tool. In this Ansible playbook, the hosts key is first used in YAML syntax to define the hosts of the inventory on which the playbook should run. The tasks key is then used to define all the tasks that are to run in this order. In an Ansible course, topics such as Ansible Playbook are usually covered.
Ansible Shell: How can Ansible access the host file in the directory by default?
Ansible is a configuration management program. With the help of this program, it is possible to run installation and configuration routines simultaneously on any number of other computers from one computer. The only prerequisite for this is that the user logged on to the tower can log on to the other computers via SSH (SSH key) and, if necessary, obtain SuperUser rights there. However, no additional software needs to be installed on the clients themselves. When Ansible is called, the path of the desired hosts file can be explicitly specified using the "-i hostfile" option. However, if you want Ansible to use the host file in the "~/ansible" directory by default, you can enter the following line in an Ansible shell (or insert it at the end of the configuration file "~/.bashrc or ~/.zshrc").
One advantage of Ansible is that it checks the existing conditions beforehand. Only then are any routines called if required. If, for example, the desired programs have already been installed or the corresponding configuration files have been adapted, no changes are made. Because of such features, Ansible is often used for server administration, as it does not restart an active server service. However, Ansible Service can also be used on standard computers. Docker containers can also be configured with Ansible Docker.
What is Ansible Tower?
Ansible is part of Red Hat's enterprise IT systems management product group and includes Satellite infrastructure management, CloudForms cloud management and the Red Hat Insights monitoring and troubleshooting service. Ansible Engine provides enterprise-level support for the open source project. Ansible Engine is a stabilized, hardened version of the upstream automation technologies. Ansible Engine includes the central task runner and modules for core functions, networking, community and other areas. Ansible Tower provides a range of management and access control features to extend the capabilities of Ansible Engine. Ansible Tower is a supported Red Hat offering based on the upstream AWX project. The IT operations team can easily control user credentials for managed systems thanks to Role Based Access Control (RBAC). Ansible Tower also includes customizable dashboards and inventory management via a Graphic User Interface (GUI), a notification system and job scheduling. In addition to the GUI, Ansible Tower has its own CLI. Tower users can use its API to integrate Ansible into development, IT and DevOps processes and toolchains. Instance groups and isolated nodes enable precise control over implementations.
What is Ansible Galaxy and how can it be used - among other things for Ansible Collections?
Ansible is an open source automation tool. It is used for orchestration and general configuration and administration of computers. It combines software distribution, ad-hoc command execution and configuration management. Network computers are managed via SSH, among other things. The advantage of Ansible is that it does not require any additional software on the system to be managed. And modules can be written in any programming language, as they use JSON for output. The system, on the other hand, uses YAML to formulate reusable descriptions of systems. One Ansible example (Ansible Example) is Ansible Galaxy. With Ansible Galaxy, it is even possible to create your own Ansible repositories. The Ansible Galaxy source code published under a free license by Red Hat is the official community hub for sharing Ansible roles. With the Ansible Galaxy open source project, companies can set up their own Galaxy server. This allows you to use the native Ansible client for forwarding m private Galaxy repository. In addition, users and companies can now contribute new features and extensions directly to the Galaxy codebase.
An Ansible Collection can contain various Ansible components: Ansible Roles, Ansible Modules or Ansible Plugins. You can make content available by installing the Ansible Collections (collection of your own Ansible environment). The "Namespace" form prevents naming collisions with Ansible Collections and namespaces have no relation to Ansible Github handles. Ansible Collections are packed and pushed to Ansible Galaxy and can be hosted on any Git respostory - private or public. The namespace is defined in the galaxy.yml metafile. Ansible Galaxy is usually covered in an Ansible course.
What is the significance of Ansible for programming?
The importance of Ansible for programming is:
- Ansible is one of the preferred tools for automating processes. This refers to processes that would otherwise take a lot of time and often have to be carried out manually without professional quality control. Ansible offers several advantages over other tools of this type (e.g. Puppet, Chef, SaltStack etc.).
- Thanks to its minimal features, Ansible is easy to use with consistent efficiency. The system status is described using easy-to-write and read YAML files (= Ansible Playbooks).
- The tasks are controlled and grouped using playbooks. You write everything in the way you want the system to work. Frequently recurring elements are stored in playbook roles and can therefore be used multiple times.
- You don't need to install much, because all you need on the system is an SSH server, Ansible Git (Ansible Github) and a current Python installation (a scripting language that comes with every current Linux system).
- And the learning curve is steep. Ansible helps to retain the knowledge in the configuration (Ansible setup) so that a DevOps successor can simply continue working where they left off at any time. This is because the code serves as documentation and everything is reproducible.
Ansible Tutorial: How can I manage files with an Ansible File?
With an Ansible file, you can manage files with the help of Ansible modules. Files can also be copied, edited, inserted, downloaded or replaced with Ansible. According to the Ansible tutorial, files can be copied from the "Ansible File" directory using the "copy" module. The "template" module, on the other hand, copies the Jinja2 template from the "template" directory to Ansible Playbooks. According to the Ansible tutorial, Ansible Copy is therefore only suitable for copying persistent files such as certificates. The "Template" module, on the other hand, is more suitable for reusable configurations such as virtual host configurations. The Ansible module "Fetch" is suitable for downloading a file from the remote machine to a local Ansible node. According to the Ansible tutorial, the following options are available for editing files with Ansible:
- Insert several lines into a file with the Ansible module "blockinfile"
- Insert several lines with the marker options with marker option "insertafter" or "insertbefore"
- Delete/remove several lines by blocking the surroundings within the markings
- Insert new line in file with "PermitEmptyPasswords"
- Remove line from file with the line file module
- Replacing pattern strings with regular expressions and replacing the module with "Replace"
- Uncommented configurations with "server tokens"
- Commentary on the configuration line
According to the Ansible tutorial, file attributes can be set via the file module in Ansible, e.g. via a symlink file or by creating a new directory using the file module. There are therefore numerous ways to manage files with an Ansible file.
To get Ansible, the most popular tool for configuration management and infrastructure automation, running on Windows, follow the Ansible documentation for "Ansible Windows". The "Ansible Install" succeeds with Cygwin - a POSIX-compatible environment that can be run on Windows. This is because you can do many things on Windows that you normally do on UNIX-based operating systems. The default installation of Cygwin does not cover Ansible, so you need to select "Download Cygwin" during installation. Using Ubuntu on Windows 10 is also an option.
How are Ansible templates used and why is the Ansible Loop so important?
Playbooks use a simple descriptive language based on YAML and Jinja templates. Templates can be inherited with Jinja2. Generally valid elements can be defined in a base template. Parts of child templates can be overwritten in so-called "blocks". A specific Ansible template is used for the website. The variables included there in Jinja syntax are then filled in by Ansible when the file is copied to the desired location using the template module. Template files are given the file extension .j2. The Ansible template file and the stylesheet are then used to create an exact folder structure. The following task is similar to restarting the firewall service: If the index file or the stylesheet changes during deployment, nginx can be restarted or the delivered files can be changed during operation. The last task should now set a message as "Message-of-the-day", which is displayed when the server logs in via SSH. Again, the Ansible template module is used to copy the desired file to etc/motd. A motd.j2 template file is therefore added. The ansible_* variables come from the host facts in the same way as the website template. However, this does not apply to webserver_name, as this variable should be different for each server and must therefore be defined accordingly.
Each Ansible module can be written independently and in any programming language. The modules should be idempotent in the sense of an "Ansible loop". This means that even if a process is repeated several times - e.g. when recovering from a failure - the system is always restored to the same state.
What are the reasons for using the Ansible Copy module to change individual file lines?
It is often necessary to change individual file lines. However, many lineinfile or blockinfile modules are used for this purpose. However, practical experience shows that these modules should not be used if files are to be changed with them. In this case, it is better to use the template or copy module. In particular, to manage not only individual lines, but the entire file. There are two reasons for this:
- When using lineinfile, regex must often be used. This results in the following problems: The use of regex is often complicated and people who then use playbooks must be familiar with regex.
- The programmer himself must know and be able to remember that this particular line in this one configuration file is managed by Ansible.
If you manage the entire file with an Ansible template, you can use theansible_managed variable to make it clear that the file is under Ansible control. Another advantage is that you can use a variable for the selinux-state and simply change it on servers where selinux should not be in the enforcing state.
Erfahrungen, Bewertungen und Meinungen zur Ausbildung / Weiterbildung
Haven't found the right training or further education yet? Benefit from educational advice now!
Further training is not only important in order to maintain or increase professional attractiveness, investing in training or further training is still the most efficient way to increase the chances of a pay rise.
The Swiss education system offers a wide range of individual training and further education opportunities - depending on your personal level of education, professional experience and educational goals.
Choosing the right educational offer is not easy for many prospective students.
Which training and further education is the right one for my path?
Our education advisory team will guide you through the "education jungle", providing specific input and relevant background information to help you choose the right offer.
Your advantages:
You will receive
- Suggestions for suitable courses, seminars or training programs based on the information you provide in the questionnaire
- An overview of the different levels and types of education
- Information about the Swiss education system
We offer our educational counseling in the following languages on request: French, Italian, English
Register now and concretize your training plans.
Sofort zur richtigen Weiterbildung
Attraktive Services für Swisscom Mitarbeitende
Kostenlose Services
» Bildungsberatung (Wert: CHF 150.–)
Bildungs- und Businessratgeber (Wert: CHF 175.–)
» Rabatte
Attraktive Rabattierungen seitens der Bildungsanbieter.
» Massgeschneiderte Bildungsangebote
Ohne grossen Zeitaufwand den besten Trainer, Coach oder Schulungsanbieter finden
Bildungsangebot Schweiz
Aus über 700 Bildungsanbietern das richtige Bildungsangebot finden