Skip to content

somaz94/ansible-k8s-iac-tool

Repository files navigation

Ansible K8s IaC Tool

Ansible Galaxy Molecule Test Release GitHub tag License

An Ansible collection for automating the installation and configuration of Kubernetes and IaC (Infrastructure as Code) tools.


Included Roles

Role Description
setup_shell Configure shell completions and PATH (bash, zsh, fish)
install_kubectl Install and configure kubectl
install_krew Install krew (kubectl plugin manager)
install_krew_plugins Install specified krew plugins
install_helm Install Helm package manager
install_terraform Install HashiCorp Terraform
install_packer Install HashiCorp Packer
install_vagrant Install HashiCorp Vagrant
install_kustomize Install Kustomize
install_pulumi Install Pulumi

Requirements

  • Ansible 2.9+
  • Supported OS: Ubuntu 22.04+, Debian 11+, Rocky Linux 9+
  • Supported Shells: bash, zsh, fish

Installation

ansible-galaxy collection install somaz94.ansible_k8s_iac_tool

Usage


Variables

Define variables in vars.yml:

home_user: "somaz"
user_shells:
  - bash          # default
  # - zsh         # optional: configure .zshrc
  # - fish        # optional: configure fish config
krew_plugins:
  - ctx
  - neat
  - ns
  # See: https://krew.sigs.k8s.io/plugins/
Variable Description Default
home_user Target user for tooling setup -
user_shells List of shells to configure (bash, zsh, fish) [bash]
krew_plugins List of krew plugins to install []

Running Locally

# site.yml
---
- hosts: localhost
  become: true
  vars_files:
    - vars.yml
  collections:
    - somaz94.ansible_k8s_iac_tool
  roles:
    - setup_shell
    - install_kubectl
    - install_krew
    - install_krew_plugins
    - install_terraform
    - install_packer
    - install_vagrant
    - install_helm
    - install_kustomize
    - install_pulumi
ansible-playbook site.yml

Running Remotely

# inventory.ini
[servers]
my-server ansible_ssh_user=ubuntu ansible_ssh_private_key_file=~/.ssh/id_rsa
# site.yml
---
- hosts: servers
  become: true
  vars_files:
    - vars.yml
  collections:
    - somaz94.ansible_k8s_iac_tool
  roles:
    - setup_shell
    - install_kubectl
    - install_krew
    - install_krew_plugins
    - install_terraform
    - install_packer
    - install_vagrant
    - install_helm
    - install_kustomize
    - install_pulumi
ansible-playbook -i inventory.ini site.yml

Post-Task

After the playbook completes, reload the shell configuration:

# bash
source ~/.bashrc

# zsh
source ~/.zshrc

# fish (new session or)
source ~/.config/fish/conf.d/k8s-iac-tools.fish

Development


Prerequisites

  • Python 3.x
  • Docker (for Molecule testing)

Quick Start

make venv                          # Create venv and install dependencies
make test                          # Full molecule test (default: ubuntu2204)
make test DISTRO=ubuntu2404        # Test with Ubuntu 24.04
make test DISTRO=debian12          # Test with Debian 12
make test DISTRO=rockylinux9       # Test with Rocky Linux 9
make converge                      # Apply roles only
make verify                        # Run verification only
make destroy                       # Destroy test instances
make lint                          # Run ansible-lint
make build                         # Build Galaxy collection
make publish GALAXY_API_KEY=xxx    # Publish to Ansible Galaxy
make clean                         # Remove venv and build artifacts

License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.