From 3dc0c341df2c2646380ae456fcb9752b977a27d4 Mon Sep 17 00:00:00 2001 From: Ted Cook Date: Tue, 5 Dec 2023 18:09:31 -0600 Subject: [PATCH] Rename role --- .github/workflows/lint.yml | 4 ++-- .github/workflows/molecule.yml | 4 ++-- .github/workflows/release.yml | 4 ++-- .talismanrc | 2 ++ README.md | 19 ++++++--------- defaults/main.yml | 5 ++-- meta/main.yml | 6 ++--- molecule/default/converge.yml | 7 ++---- molecule/default/molecule.yml | 2 +- molecule/default/prepare.yml | 5 ---- molecule/default/verify.yml | 4 ---- pyproject.toml | 2 +- tasks/main.yml | 44 ++++++++++++++++++++++++++++------ 13 files changed, 62 insertions(+), 46 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 7bd7c05..02a15fd 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -10,7 +10,7 @@ on: defaults: run: - working-directory: 'nephelaiio.kubectl' + working-directory: 'nephelaiio.k8s_repo' jobs: @@ -22,7 +22,7 @@ jobs: - name: Check out the codebase uses: actions/checkout@v4 with: - path: 'nephelaiio.kubectl' + path: 'nephelaiio.k8s_repo' - name: Set up python 3 uses: actions/setup-python@v4 diff --git a/.github/workflows/molecule.yml b/.github/workflows/molecule.yml index a029133..ca20853 100644 --- a/.github/workflows/molecule.yml +++ b/.github/workflows/molecule.yml @@ -12,7 +12,7 @@ on: defaults: run: - working-directory: 'nephelaiio.kubectl' + working-directory: 'nephelaiio.k8s_repo' jobs: @@ -37,7 +37,7 @@ jobs: - name: Check out the codebase uses: actions/checkout@v4 with: - path: 'nephelaiio.kubectl' + path: 'nephelaiio.k8s_repo' - name: Set up python 3 uses: actions/setup-python@v4 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a39843d..5d25ca9 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -14,7 +14,7 @@ on: defaults: run: - working-directory: 'nephelaiio.kubectl' + working-directory: 'nephelaiio.k8s_repo' jobs: @@ -26,7 +26,7 @@ jobs: - name: Check out the codebase. uses: actions/checkout@v4 with: - path: 'nephelaiio.kubectl' + path: 'nephelaiio.k8s_repo' - name: Set up Python 3 uses: actions/setup-python@v4 diff --git a/.talismanrc b/.talismanrc index ce74465..80b07ab 100644 --- a/.talismanrc +++ b/.talismanrc @@ -1,5 +1,7 @@ fileignoreconfig: - filename: poetry.lock ignore_detectors: [filecontent] + - filename: defaults/main.yml + ignore_detectors: [filecontent] - filename: .github/workflows/release.yml ignore_detectors: [filecontent] diff --git a/README.md b/README.md index 41d2970..5fa898d 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,9 @@ -# nephelaiio.kubectl +# nephelaiio.k8s_repo -[![Build Status](https://github.com/nephelaiio/ansible-role-kubectl/actions/workflows/molecule.yml/badge.svg)](https://github.com/nephelaiio/ansible-role-kubectl/actions/wofklows/molecule.yml) -[![Ansible Galaxy](http://img.shields.io/badge/ansible--galaxy-nephelaiio.kubectl.vim-blue.svg)](https://galaxy.ansible.com/nephelaiio/kubectl/) +[![Build Status](https://github.com/nephelaiio/ansible-role-k8s-repo/actions/workflows/molecule.yml/badge.svg)](https://github.com/nephelaiio/ansible-role-k8s-repo/actions/wofklows/molecule.yml) +[![Ansible Galaxy](http://img.shields.io/badge/ansible--galaxy-nephelaiio.k8s-repo.vim-blue.svg)](https://galaxy.ansible.com/nephelaiio/k8s-repo/) - - -An [ansible role](https://galaxy.ansible.com/nephelaiio/kubectl) to install and configure kubectl +An [ansible role](https://galaxy.ansible.com/nephelaiio/k8s-repo) to install and configure Kubernetes package repostiories ## Role Variables @@ -21,8 +17,7 @@ By default this role does not depend on any external roles. If any such dependen - hosts: servers roles: - - role: nephelaiio.kubectl - kubectl_package_state: latest + - role: nephelaiio.k8s_repo ## Testing @@ -30,10 +25,10 @@ Please make sure your environment has [docker](https://www.docker.com) installed Role is tested against the following distributions (docker images): - * Ubuntu Focal * Ubuntu Jammy - * Debian Buster + * Ubuntu Focal * Debian Bullseye + * Debian Bookworm You can test the role directly from sources using command ` molecule test ` diff --git a/defaults/main.yml b/defaults/main.yml index a03642f..47dc9cc 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,3 +1,4 @@ --- -# kubectl_release: v1.28 -kubectl_state: present +# k8s_repo_release: v1.28 +k8s_repo_state: latest +k8s_repo_keyring_debian: /etc/apt/keyrings/kubernetes-apt-keyring.gpg diff --git a/meta/main.yml b/meta/main.yml index 0f6078c..102bb34 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -1,8 +1,8 @@ --- galaxy_info: - role_name: kubectl + role_name: k8s_repo author: nephelaiio - description: An Ansible role to install and configure kubectl + description: An Ansible role to configure K8s package repositories license: MIT min_ansible_version: '2.15' platforms: @@ -15,6 +15,6 @@ galaxy_info: - name: Debian versions: - all - galaxy_tags: ['kubectl'] + galaxy_tags: ['k8s', 'k8s_repo', 'repo', 'repository'] dependencies: [] diff --git a/molecule/default/converge.yml b/molecule/default/converge.yml index 5428bef..79d2c11 100644 --- a/molecule/default/converge.yml +++ b/molecule/default/converge.yml @@ -1,9 +1,6 @@ --- - name: Converge - hosts: all - + become: true roles: - - - nephelaiio.plugins - - nephelaiio.kubectl + - nephelaiio.k8s_repo diff --git a/molecule/default/molecule.yml b/molecule/default/molecule.yml index 8fdad5f..404904f 100644 --- a/molecule/default/molecule.yml +++ b/molecule/default/molecule.yml @@ -7,7 +7,7 @@ dependency: driver: name: docker platforms: - - name: kubectl-install-01 + - name: k8s-repo-install-01 image: "geerlingguy/docker-${MOLECULE_DOCKER_IMAGE:-ubuntu2004}-ansible:latest" command: ${MOLECULE_DOCKER_COMMAND:-""} cgroupns_mode: host diff --git a/molecule/default/prepare.yml b/molecule/default/prepare.yml index b4ddabb..edd50df 100644 --- a/molecule/default/prepare.yml +++ b/molecule/default/prepare.yml @@ -1,14 +1,9 @@ --- - name: Prepare - hosts: all - gather_facts: true - become: true - tasks: - - name: Update apt package cache ansible.builtin.apt: update_cache: yes diff --git a/molecule/default/verify.yml b/molecule/default/verify.yml index cd1600c..ec450ea 100644 --- a/molecule/default/verify.yml +++ b/molecule/default/verify.yml @@ -1,10 +1,6 @@ --- - name: Verify - hosts: all - gather_facts: true - become: true - tasks: diff --git a/pyproject.toml b/pyproject.toml index 20ffb56..23c2495 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [tool.poetry] -name = "nephelaiio.kubectl" +name = "nephelaiio.k8s_repo" version = "0.1.0" description = "" authors = ["nephelaiio"] diff --git a/tasks/main.yml b/tasks/main.yml index 4a3b8a5..a5db8f5 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,22 +1,52 @@ --- -- name: Set kubectl install target release +- name: Set Kubernetes repository version ansible.builtin.set_fact: - kubectl_version: "{{ lookup('ansible.builtin.url', 'https://dl.k8s.io/release/stable.txt', split_lines=False) }}" - when: kubectl_version is not defined + k8s_repo_version: "{{ lookup('ansible.builtin.url', 'https://dl.k8s.io/release/stable.txt', split_lines=False) }}" + when: k8s_repo_version is not defined -- name: Set kubectl release facts +- name: Set Kuberentes repository release facts ansible.builtin.set_fact: - _kubectl_target: "{{ '.'.join(kubectl_version.split('.')[0:2]) }}" + _k8s_repo_target: "{{ '.'.join(k8s_repo_version.split('.')[0:2]) }}" -- name: Deploy on Debian systems +- name: Configure Kubernetes apt repository when: ansible_os_family == "Debian" block: + - name: Create tempfile + ansible.builtin.tempfile: + suffix: k8s + + - name: Set distribution facts + ansible.builtin.set_fact: + _apt_repo_url: "https://pkgs.k8s.io/core:/stable:/{{ _k8s_repo_target }}/deb" + - name: Install Debian package helpers ansible.builtin.package: name: - apt-transport-https - ca-certificates + - curl + + - name: Create keyring directory + ansible.builtin.file: + path: "{{ k8s_repo_keyring_debian | dirname }}" + state: directory + owner: root + group: root + mode: 0755 + + - name: Install gpg certificate + ansible.builtin.shell: + cmd: >- + curl -fsSL {{ _apt_repo_url }}/Release.key | gpg --dearmor -o {{ k8s_repo_keyring_debian }} + executable: /bin/bash + changed_when: false + + - name: Configure apt repository + ansible.builtin.apt_repository: + filename: k8s_repo + repo: "deb [signed-by={{ k8s_repo_keyring_debian }}] {{ _apt_repo_url }} /" -- name: Deploy on RedHat systems +- name: Configure Kubernetes yum repository when: ansible_os_family == "RedHat" block: + - fail: