Ansible Molecule with Kind - Kubernetes Automation Testing with Docker

Introduction to Ansible Molecule with KIND Learn how to set up a Kubernetes automation testing environment by combining Ansible Molecule with KIND (Kubernetes IN Docker). Overview Ansible Molecule Ansible Molecule is a framework that helps test Ansible Roles in isolated environments using virtualization technologies. It supports various drivers and can integrate with KIND using the Delegated driver for Kubernetes environments. KIND (Kubernetes IN Docker) KIND is a tool that runs Kubernetes clusters as Docker containers. It allows you to quickly and easily create Kubernetes clusters locally, making it useful for: ...

2022-05-26 · 13 min · 2723 words · Sung-Kyu Yoo

Testing Ansible Roles with Molecule

Introduction to Molecule Molecule is a testing framework for Ansible Roles maintained by the ansible-community. With Molecule, you can systematically test Ansible Roles, enabling comprehensive testing using multiple instances, operating systems, virtualization providers, test frameworks, and test scenarios. Why Do You Need Molecule? When developing Ansible Roles, you face the following challenges: Limitations of Manual Testing: Manually running and verifying Roles each time is time-consuming. Multi-Environment Support: You need to ensure Roles work correctly on various operating systems like Ubuntu, CentOS, and Debian. Continuous Integration: Tests need to run automatically in CI/CD pipelines. Code Quality: Ansible code quality must be maintained consistently. Molecule provides the following features to address these challenges: ...

2022-05-26 · 10 min · 2031 words · Sung-Kyu Yoo

Developing Ansible Modules

Ansible provides features that make it relatively easy to write automation for large-scale server installation, application deployment, and service operations. It’s one of the methods enabling DevOps, Ansible runs over SSH and requires SSH access to remote machines. No separate daemons or agents are needed. Remote machines (for default Ansible Modules) only need Python 2.6 or higher installed. (Some modules may require additional Python modules.) Ansible Modules are recommended to guarantee idempotency. For modules that exceptionally don’t guarantee idempotency, be sure to document warnings. Introduction An Ansible Module can be thought of as a set of functions with a specific purpose in one Task of an Ansible Playbook. For example, if you need to “move a file from path A to path B”, you can use the “file” module provided by default in Ansible. ...

2017-11-14 · 8 min · 1636 words · Sung-Kyu Yoo

Introduction to Ansible Callback Plugin

This article focuses only on Callback Plugin among Ansible Plugins. Callback Plugin is a module used for various purposes such as logging data when specific events occur in Ansible, or writing to external channels like Slack, Mail, etc. This content is based on Ansible 2.2.1.0. What is Callback Plugin? Introduction Ansible Callback Plugin refers to plugins that can hook into various Ansible events and execute desired logic at those points. These callback plugins support defining callback functions for events like “before execution” and “after execution” for Ansible Tasks, Playbooks, etc. ...

2017-11-14 · 9 min · 1741 words · Sung-Kyu Yoo

Ansible Galaxy - Managing Role Dependencies Using Git Repositories

Uploading Ansible Role to Git Repository First, create a Git repository for developing an Ansible Role. Then, generate the initial Ansible Role project structure using Ansible Galaxy. Clone the Git repository to your local machine. 1 $ git clone "https://github.com/xxxxx/sample-role.git" Generate Ansible Role initial directory and files. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 $ ansible-galaxy init --force sample-role - sample-role was created successfully $ tree sample-role/ sample-role/ ├── README.md ├── defaults │ └── main.yml ├── files ├── handlers │ └── main.yml ├── meta │ └── main.yml ├── tasks │ └── main.yml ├── templates ├── tests │ ├── inventory │ └── test.yml └── vars └── main.yml After developing the Ansible Role, push to Git repository. 1 $ git commit * -m "Add ansible role" && git push Downloading Ansible Role from Git Repository Method 1) Download via Ansible Galaxy CLI 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 $ ansible-galaxy install git+https://github.com/xxxx/sample-role.git,master -p roles/ $ tree roles/ roles/ └── sample-role ├── README.md ├── defaults │ └── main.yml ├── handlers │ └── main.yml ├── meta │ └── main.yml ├── tasks │ └── main.yml ├── tests │ ├── inventory │ └── test.yml └── vars └── main.yml Method 2) Specify in dependency file and download via CLI 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 $ vi requirements.yml - src: git+https://github.com/xxxx/sample-role.git version: master $ ansible-galaxy install -r requirements.yml -p roles/ - extracting sample-role to roles/sample-role - sample-role was installed successfully $ tree roles/ roles/ └── sample-role ├── README.md ├── defaults │ └── main.yml ├── handlers │ └── main.yml ├── meta │ └── main.yml ├── tasks │ └── main.yml ├── tests │ ├── inventory │ └── test.yml └── vars └── main.yml Writing ‘requirements.yml’ src username.role_name: Used to download Ansible Roles registered in the official Ansible Galaxy repository. url: Used to download from SCMs supported by Ansible Galaxy. scm Specify the SCM name to integrate. Default is ‘git’ (as of ansible-galaxy 2.2.1.0, only git and hg are supported) version Specify tag name / commit hash / branch name. Default is ‘master’ Only used when downloading from SCM. name Specify the name of the downloaded Ansible Role. By default, uses the name registered in Ansible Galaxy or the Git repository name. See the examples below: ...

2017-02-16 · 7 min · 1425 words · Sung-Kyu Yoo