Molecule-based role skeleton for use with ansible-galaxy to create a new ansible role.
This README does not explain how to use molecule. Please read the docs if you need to.
Table of Contents
- include os specific variables
- first a
vars/{{ansible_os_family}}.yml
is included, automatically created when using this skeleton (e.g.RedHat.yml
orArchlinux.yml
) - then the first found of the following, if you create them (e.g.
Fedora-31.yml
)vars/{{ ansible_distribution }}-{{ ansible_distribution_major_version }}.yml
vars/{{ ansible_distribution }}.yml
vars/{{ ansible_os_family }}-{{ ansible_distribution_major_version }}.yml
- first a
- install os specific packages
- use predefined containers for testing, see ansible-molecule-images
- have a predefined README.md skeleton
- use consistent comments in each
yml
-file
---
# role: ansible-role-foreman
# file: defaults/main.yml
# Default variables for foreman
Listing 1: Code Example of a newly generated role skeleton for ansible-role-foreman
git clone https://github.com/jomrr/skeleton-ansible-role
ansible-galaxy role init --role-skeleton=./skeleton-ansible-role <rolename>
For a more convenient way see Usage.
For all scenarios the following is required
- python3 (install via your os package manager)
- Ansible 2.17 or higher
pipx install ansible
Then you can install the required python3 modules for all scenarios as an unprivileged user with the folliwing command:
pipx inject --indlcude-deps ansible ansible-lint molecule molecule-plugins[podman] molecule-plugins[vagrant] jmespath keyring
For running the default tests with molecule podman you just need to install podman.
To use the predefined tests with vagrant libvirt you need to have the following packages installed:
- qemu
- virt-manager
- libvirt-dev(el) package, dependnt on your os
- vagrant
Your user needs to be in the libvirt
or libvirtd
system group depending on your distribution, because the qemu system domain is used.
After installing vagrant you need the vagrant-libvirt
plugin.
You can install it with:
vagrant plugin install vagrant-libvirt
Podman should work out of the box, after it is installed.
To install it, see the official instructions or you can also use my ansible-role-podman.
To create a new ansible role with this skeleton, do the following:
git clone https://github.com/jomrr/skeleton-ansible-role.git
ansible-galaxy role init --role-skeleton=./skeleton-ansible-role <rolename>
If you want to use it in a more convenient way, create a custom function e.g. in ~/.bashrc
# ansible-galaxy init with custom role-skeleton
ag-role() {
if [ -z "$1" ]; then
echo "Please specify a role name that will be appended to <rolename>"
return 1
fi
ansible-galaxy role init --role-skeleton=${2:-'./skeleton-ansible-role'} $1
}
Then you are able to issue for example
ag-role dhcpd
to create a role skeleton for ansible-role-dhcpd.
Licensed under MIT License. See LICENSE file in repository.