Skip to content

while-true-do/ansible-skeleton

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

96 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Github (tag) Github (license) Github (issues) Github (pull requests)

Travis (com)

Ansible Skeleton

A Skeleton for developing Ansible Code for while-true-do.io.

Motivation

Creating a repository is always somewhat interesting and needs a lot explanation. This repository should help to reduce the effort and prepare a ready-to-use environment.

Description

This repository consists of several guidance and skeletons for Ansible:

  • provide template for new ansible roles
  • provide defaults for new ansible roles
  • provide steps for new ansible roles
  • provide guidance for ansible new roles

Coding Conventions

You can find the while-true-do.io conventions in the docs.

Requirements

Installation

Install from Github

git clone https://github.com/while-true-do/ansible-skeleton.git

Usage

Before creating a new role, please read the below information very carefully. They will explain, how a new role should look like and which steps are needed.

Install Ansible

The recommended and portable way to install Ansible is via virtualenv.

# Create a new virtualenv
virtualenv $env_name
# Activate virtualenv
source $env_name/bin/activate
# Install Ansible
pip install ansible

On some selinux enabled systems like Fedora, you have to symlink the selinux site-packages manually.

# Search local site-packages
find /usr/lib64 -iname "*selinux*"
# Now you have to symlink the selinux directory and the python-c-bindings
# Example:
cd $env_name
ln -s /usr/lib64/python3.7/site-packages/_selinux.cpython-37m-x86_64-linux-gnu.so ./lib/python3.7/site-packages/selinux
ln -s /usr/lib64/python3.7/site-packages/_selinux.cpython-37m-x86_64-linux-gnu.so ./lib/python3.7/site-packages/_selinux.cpython-37m-x86_64-linux-gnu.so

Furthermore, selinux requires you to allow docker to manage cgroups.

setsebool -P container_manage_cgroup on

Configure Ansible

Ansible configuration can be done in multiple files, depending on your needs.

# Edit system ansible.cfg
sudo vi /etc/ansible/ansible.cfg

# Edit user ansible.cfg
vi ~/.ansible.cfg

# Add one to the specific role
vi ansible.cfg (in the current directory)

You have to add the following lines:

[galaxy]
role_skeleton = <path_to_ansible-skeleton>/role
role_skeleton_ignore = ^.git$,^.*/.git_keep$

Install Molecule

Molecule must be installed in the same virtualenv (see above).

# Activate virtualenv
source $env_name/bin/activate
# Install molecule and docker support
pip install molecule[docker]

Create Ansible Role

Some manual steps are needed to create new role from scratch.

# Step 1: Create Directory from skeleton
ansible-galaxy init $role_name
mv $role_name while_true_do.$role_name

# Step 2: Review and Modify all "TODO" steps
grep -r "TODO" while_true_do.$role_name

Add Tests to the role

Testing is key for new roles. You want to get comfortable with the Ansible Testing Convention.

Testing

This repository is not tested.

Contribute

Thank you so much for considering to contribute. We are very happy, when somebody is joining the hard work. Please fell free to open Bugs, Feature Requests or Pull Requests after reading the Contribution Guideline.

See who has contributed already in the kudos.txt.

License

This work is licensed under a BSD-3-Clause License.

Contact