Skip to content

Skeleton for use with ansible-galaxy to create a new ansible role.

License

MIT, MIT licenses found

Licenses found

MIT
LICENSE
MIT
LICENSE.j2
Notifications You must be signed in to change notification settings

jomrr/skeleton-ansible-role

Repository files navigation

skeleton-ansible-role

GitHub GitHub last commit GitHub issues Travis (.com) branch

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

Features

  • include os specific variables
    • first a vars/{{ansible_os_family}}.yml is included, automatically created when using this skeleton (e.g. RedHat.yml or Archlinux.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
  • 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

Quickstart

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.

Requirements

For all scenarios the following is required

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

Podman Scenario (default)

For running the default tests with molecule podman you just need to install podman.

Libvirt Scenario (kvm)

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 Scenario (podman)

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.

Usage

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.

Author(s) and License

  • :octocat: Author:: jomrr
  • 🚩 Copyright:: 2020, Jonas Mauer
  • 📃 License:: MIT

Licensed under MIT License. See LICENSE file in repository.

About

Skeleton for use with ansible-galaxy to create a new ansible role.

Topics

Resources

License

MIT, MIT licenses found

Licenses found

MIT
LICENSE
MIT
LICENSE.j2

Stars

Watchers

Forks

Languages