Molecule is the official testing framework for Ansible roles. It provides a streamlined way to create a virtualized environment to test the syntax and functionality of a role.
Continue reading →
VirtualBox is a general-purpose full virtualizaton for x86 hardware, targeted at server, desktop and embedded use. The VirtualBox Guest Additions are extra pieces of software that enable better performance and functionality in virtual machines. We install Guest Additions inside the virtual machine to activate this functionality. In VirtualBox, we can install Guest Additions by selecting…
Continue reading →
Configuring the network interfaces of Linux machines can be tedious and unpredictable if we do it by hand. Let’s automatize the procedure and minimize the possible mistakes with using Ansible! This example uses Debian, but it can be easily ported to any platform. Here’s my example playbook that can be used to configure network for…
Continue reading →
Docker Engine is an open source containerization technology for building and containerizing our applications. Docker Engine acts as a client-server application with a server with a long-running daemon process dockerd and APIs which specify interfaces that programs can use to talk to and instruct the Docker daemon. Docker Engine is available on a variety of…
Continue reading →
Ansible Galaxy is a hub for finding and sharing Ansible content, such as roles and collections. Roles are pre-packaged units of work that can be referenced in Ansible playbooks and immediately put to work. Collections are larger units that can contain multiple roles, modules, plugins, and other Ansible components.
Continue reading →
As our infrastructure grows, we may have to use secret data of different sensitivity. If our “Infrastructure as Code” is developed by different teams, maybe every team wants to protect their own passwords, API tokens, keys, etc with different Vault passwords. This is why we use IDs in Ansible Vault.
Continue reading →
Sometimes we may want to encrypt only a single variable value or a short piece of text that we need to use in our playbook or role. For example, we may want to encrypt a user password or an API key, and not an entire file. Encrypting single variables is also a good idea when we keep our files in Source Control Management like Git.
Ansible Vault has a function to encrypt only parts of files, to encrypt variables instead of the whole file.
Continue reading →
Templating is a huge work power in Ansible when we want to write reusable code. Just imagine about having to create different playbooks and roles for every host that have a slightly different configuration from each other. That would be nonsense. Luckily we have configuration file templates in Ansible to make our life easier, and…
Continue reading →
Previously we took a look at creating a basic plain text file inventory for our Ansible automation project, but we will need more functionality when we start using it seriously. Luckily Ansible provides us some other ways to create groups of hosts and handle them. Let’s investigate what else can we do in an Ansible…
Continue reading →
Handlers are Ansible’s solution for running specific operations only when other tasks made changes, like when we update the configuration of a web server, and we want to restart the service. Obviously we do not want to restart the Apache2 on every playbook run, only if there is a change in its configuration. This is…
Continue reading →
There are some limitations of using YAML instead of a scripting language or a DSL, but the developers of Ansible thought about the issue, and they integrated some cool, more advanced features into the tool. We can use blocks collecting and handling tasks together Let’s investigate this feature a bit more!
Continue reading →
When we automate configurations we cannot avoid providing secrets to Ansible. The last thing we want is our secret data running around in plain text files on our control node. Luckily Ansible has a tool for this. Ansible Vault is an integrated encryption tool in Ansible to manage sensitive data like passwords, keys and certificates.…
Continue reading →
In a playbook or in a role sometimes we want to run different tasks based on different conditions. In most cases it depends on a fact (detail about the managed host) or some data collected during the playbook run. Ansible conditionals are there to make it possible to run different tasks based on different conditions,…
Continue reading →
Ansible loops and conditional statements are very cool inventions, but they are a double edged sword as well. The limitless freedom they give us can turn our roles into horrible mess. It is our responsibility to balance on the edge and use just the right amount of them in our code while we keep in…
Continue reading →
After we ran ad-hoc commands and created a monolith playbook, we will increase our level of automation. We will separate our code much better with introducing modular, reusable file structures called roles. Ansible roles will load variables, handlers and tasks automatically for us based on a defined directory and file structure.
Continue reading →