Skip to content

bcochofel/ansible-ubuntuwst-roles

Repository files navigation

Ansible Roles for Ubuntu Workstation

pre-commit badge Conventional commits badge Keep a Changelog v1.1.0 badge MIT License Badge GitHub release (latest by date)

This repository has several ansible roles and playbooks that can be used to configure Ubuntu as a Workstation.

pre-commit hooks

Read the pre-commit hooks document for more info.

git-chglog

Read the git-chglog document for more info.

TL;DR

If you just want to run the playbooks on this repo you just need to install ansible and configure it to use on the remote hosts you want to.

Check this link for more info on how to install ansible.

List of playbooks available:

playbook description
base_utils.yml Install base utilities and pip packages
cloud_tools.yml Install Azure, AWS and GCP(*) CLI tools
collab_tools.yml Collaboration tools
dev_tools.yml Development tools
i3wm.yml Install i3 Window Manager
kube_tools.yml Kubernetes administration tools
terraform_tools.yml Terraform tools for linting and compliance

(*) not yet implemented

NOTE: Before running the playbooks ensure that your inventory is configured.

run the playbooks:

ansible-playbook <playbook.yml>

to run the i3wm.yml playbook on localhost execute:

ansible-playbook -i localhost, i3wm.yml

Requirements

This repository should be used from a Python Virtual Environment.

Setup Python 3

Make sure versions are up-to-date and install git and ssh server:

sudo apt update
sudo apt -y upgrade

Check Python version:

python3 -V

Install essential tools for the development environment:

sudo apt install -y python3-pip build-essential libssl-dev libffi-dev python3-dev python3-venv git ssh

Setup Virtual Environment

Create the Virtual Environment:

git clone https://github.com/bcochofel/ansible-ubuntuwst-roles.git
cd ansible-ubuntuwst-roles
python3 -m venv .venv

Activate the environment:

source .venv/bin/activate

Install requirements.txt:

pip install --upgrade setuptools wheel pip
pip install -r requirements.txt

Install community.general collection for Ansible:

ansible-galaxy collection install community.general

You now have python virtual environment with all the dependencies installed and can start deploying the ansible roles.

Configure Ansible

You should have ssh installed and running.

Create SSH key:

ssh-keygen -t rsa

and add the public key to ~/.ssh/authorized_keys:

cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys

Ensure sudo passwordless for the ansible user by creating a file /etc/sudoers.d/bcochofel with the following contents:

bcochofel ALL=(ALL) NOPASSWD: ALL

and that the file permissions are 0440.

Install Ansible and Molecule manually

If you don't want to use the requirements.txt file you can install both ansible and molecule using the following commands:

python3 -m pip install wheel pytest testinfra flake8 pytest-testinfra pytest-flake8 cookiecutter
python3 -m pip install "molecule[ansible,lint,docker]"
# for snap module
ansible-galaxy collection install community.general

generate requirements.txt file using the following command:

pip freeze > requirements.txt

Create new Ansible Role

Ansible Role using custom Cookiecutter template

You can use custom cookiecutter templates with some pre-defined tasks or variables. You can use this repo for reference.

Go to the roles folder and execute the following commands:

cd roles/
cookiecutter gh:bcochofel/molecule-cookiecutter

answer the on-screen questions.

Ansible Role using default template

To use the default template execute the following commands:

cd roles/
molecule init role -d docker <role-name>
  • -d: docker driver

How to test the Role

Change to the role folder.

Create instance

molecule create

List instances

molecule list

Test Role against instance

molecule converge

Manual inspection

molecule login

Run Verification steps

molecule verify

Run Lint steps

molecule lint

Destroy instance

molecule destroy

Run all tests

molecule test

References