{"id":51507964,"url":"https://github.com/explicit-logic/ansible-module-15.6","last_synced_at":"2026-07-08T02:30:43.811Z","repository":{"id":363679025,"uuid":"1263352570","full_name":"explicit-logic/ansible-module-15.6","owner":"explicit-logic","description":"Automate Kubernetes Deployment","archived":false,"fork":false,"pushed_at":"2026-06-09T22:01:52.000Z","size":1392,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-06-10T00:04:35.336Z","etag":null,"topics":["ansible","aws","devops-bootcamp","eks","eks-cluster","kubernetes","linux","python","terraform"],"latest_commit_sha":null,"homepage":"","language":"HCL","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/explicit-logic.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-06-08T21:51:26.000Z","updated_at":"2026-06-09T22:08:49.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/explicit-logic/ansible-module-15.6","commit_stats":null,"previous_names":["explicit-logic/ansible-module-15.6"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/explicit-logic/ansible-module-15.6","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/explicit-logic%2Fansible-module-15.6","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/explicit-logic%2Fansible-module-15.6/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/explicit-logic%2Fansible-module-15.6/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/explicit-logic%2Fansible-module-15.6/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/explicit-logic","download_url":"https://codeload.github.com/explicit-logic/ansible-module-15.6/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/explicit-logic%2Fansible-module-15.6/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":35249883,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-07-08T02:00:06.796Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ansible","aws","devops-bootcamp","eks","eks-cluster","kubernetes","linux","python","terraform"],"created_at":"2026-07-08T02:30:43.408Z","updated_at":"2026-07-08T02:30:43.795Z","avatar_url":"https://github.com/explicit-logic.png","language":"HCL","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Module 15 - Configuration Management with Ansible\n\nThis repository contains a demo project created as part of my **DevOps studies** in the [TechWorld with Nana – DevOps Bootcamp](https://www.techworld-with-nana.com/devops-bootcamp).\n\n**Demo Project:** Automate Kubernetes Deployment\n\n**Technologies used:** Ansible, Terraform, Kubernetes, AWS EKS, Python, Linux\n\n**Project Description:**\n\n- Create EKS cluster with Terraform\n- Write Ansible Play to deploy application in a new K8s namespace\n\n---\n\n## Overview\n\n![Architecture: Terraform-provisioned EKS cluster on AWS, with Ansible deploying an app into a new Kubernetes namespace](./images/overview.png)\n\n## Prerequisites\n\nCopy and fill in the variables file:\n\n```sh\ncp terraform.tfvars.example terraform.tfvars\n```\n\n### Create EKS cluster with Terraform\n\nProvision the infrastructure:\n\n```sh\nterraform init\nterraform apply\n```\n\n\n![EKS cluster myapp-eks-cluster in the AWS console](./images/myapp-cluster.png)\n\n\n### Create a Namespace in EKS cluster\n\nGenerate a kubeconfig for the new cluster. The `--region` and `--name` must match `terraform.tfvars` and the cluster `name` in `eks-cluster.tf`:\n\n```sh\naws eks update-kubeconfig --region eu-central-1 --name myapp-eks-cluster --kubeconfig ./kubeconfig-myapp-eks-cluster\n```\n\nCreate `deploy-to-k8s.yaml` file\n\n```yaml\n---\n- name: Deploy app in new namespace\n  hosts: localhost\n  tasks:\n    - name: Create a k8s namespace\n      kubernetes.core.k8s:\n        name: my-app\n        api_version: v1\n        kind: Namespace\n        state: present\n        kubeconfig: ./kubeconfig-myapp-eks-cluster\n```\n\nDoc: https://docs.ansible.com/projects/ansible/latest/collections/kubernetes/core/k8s_module.html\n\nThe `kubernetes.core.k8s` module needs the Kubernetes Python client (plus PyYAML and jsonpatch) available to the interpreter Ansible runs with. Install them into the project environment:\n\n```sh\nuv sync\n```\n\nVerify the libraries import correctly (`uv run` uses the project virtualenv):\n\n```sh\nuv run python3 -c \"import yaml, kubernetes, jsonpatch; print('dependencies OK')\"\n```\n\n\u003e Note: PyYAML is imported as `yaml`, not `pyyaml`.\n\nThe module itself ships in the `kubernetes.core` Ansible collection. It is bundled with the `ansible` community package; if you installed `ansible-core` only, add it with:\n\n```sh\nansible-galaxy collection install kubernetes.core\n```\n\nCreate `ansible.cfg`\n\n```conf\n[defaults]\nhost_key_checking = False\ninventory = hosts\nenable_plugins = aws_ec2\nremote_user = ec2-user\nprivate_key_file = ~/.ssh/id_rsa\n```\n\nExecute the playbook\n\n```sh\nansible-playbook deploy-to-k8s.yaml\n```\n\n![Ansible playbook run creating the my-app namespace](./images/execute-playbook.png)\n\nConnect to k8s cluster\n\n```sh\nexport KUBECONFIG=./kubeconfig-myapp-eks-cluster\nkubectl get ns\n```\n\n![kubectl get ns showing the new my-app namespace](./images/kubectl-get-ns.png)\n\n### Deploy app in new namespace\n\n\nAdd deploy app step to `deploy-to-k8s.yaml`:\n```yaml\n    - name: Deploy nginx app\n      kubernetes.core.k8s:\n        src: ./nginx.yaml\n        state: present\n        kubeconfig: ./kubeconfig-myapp-eks-cluster\n        namespace: my-app\n```\n\nExecute the playbook\n\n```sh\nansible-playbook deploy-to-k8s.yaml\n```\n\nCheck the app. The `nginx` Service is of type `LoadBalancer`, so AWS provisions an external load balancer — wait until `EXTERNAL-IP` shows a hostname rather than `\u003cpending\u003e`:\n\n```sh\nkubectl get pod -n my-app\nkubectl get svc -n my-app\n```\n\n![kubectl showing the nginx pod and LoadBalancer service in my-app](./images/kubectl-get-app.png)\n\nCopy `EXTERNAL-IP` and open it in the browser:\n\n![nginx welcome page served from the EKS cluster](./images/nginx-app.png)\n\n### Set environment variable for kubeconfig\n\nInstead of passing `kubeconfig:` to every task, the `kubernetes.core` collection automatically reads the `K8S_AUTH_KUBECONFIG` environment variable:\n\n```sh\nexport K8S_AUTH_KUBECONFIG=./kubeconfig-myapp-eks-cluster\n```\n\nRemove the `kubeconfig:` lines from every task in `deploy-to-k8s.yaml`, then run the playbook again:\n\n```sh\nansible-playbook deploy-to-k8s.yaml\n```\n\n![Playbook run authenticating via the K8S_AUTH_KUBECONFIG environment variable](./images/env-var.png)\n\n### Clean-up\n\nThe `nginx` Service of type `LoadBalancer` provisions an AWS load balancer that is **not** tracked in Terraform state. Delete the Kubernetes resources first so the load balancer is released; otherwise it can orphan ENIs and block the VPC from being destroyed:\n\n```sh\nkubectl delete -f nginx.yaml -n my-app\n```\n\nThen destroy the cluster and all remaining infrastructure:\n\n```sh\nterraform destroy\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fexplicit-logic%2Fansible-module-15.6","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fexplicit-logic%2Fansible-module-15.6","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fexplicit-logic%2Fansible-module-15.6/lists"}