Rolle aktualisiert: k9s (#458)

Co-authored-by: Michael Grote <michael.grote@posteo.de>
Reviewed-on: #458
This commit is contained in:
Michael Grote 2023-02-17 11:57:35 +01:00
parent e049d339a4
commit 2b3921aa21
21 changed files with 502 additions and 30 deletions

View file

@ -3,7 +3,7 @@
restic_folders_to_backup: "/ /var" # --one-file-system ist gesetzt, also werden weitere Dateisysteme nicht eingeschlossen, es sei denn sie werden hier explizit angegeben; https://restic.readthedocs.io/en/latest/040_backup.html#excluding-files
### pandemonium1986.ansible-role-k9s
k9s_version: "v0.26.7"
k9s_version: "v0.27.3"
### mrlesmithjr.ansible-manage-lvm
#lvm_groups:

View file

@ -0,0 +1 @@
-P ubuntu-latest=nektos/act-environments-ubuntu:18.04-full

View file

@ -0,0 +1,15 @@
# EditorConfig is awesome: https://EditorConfig.org
root = true
[*]
indent_style = space
indent_size = 2
# tab_width
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
# max_line_length = 80
[*.md]
trim_trailing_whitespace = false

View file

@ -0,0 +1,17 @@
---
version: 2
updates:
# Maintain dependencies for GitHub Actions
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"
time: "09:00"
timezone: "Europe/Paris"
labels:
- "actions"
- "dependencies"
assignees:
- "Pandemonium1986"
# commit-message:
# prefix: "dependabot-action"

View file

@ -0,0 +1,13 @@
# Changes
#### Major Changes
- N/A
#### Minor Changes
- N/A
# Bug fixes
- N/A

View file

@ -0,0 +1,77 @@
---
repository:
name: "ansible-role-k9s"
description: "Ansible Role - K9s"
# homepage: https://example.github.io/
topics: "automation, k9s, ansible-role"
private: false
has_issues: false
has_projects: false
has_wiki: false
has_downloads: true
default_branch: master
is_template: false
allow_squash_merge: false
allow_merge_commit: false
allow_rebase_merge: false
# Dependabot
enable_automated_security_fixes: false
enable_vulnerability_alerts: false
labels:
# Defaults
- name: bug
color: d73a4a
description: Something isn't working
- name: documentation
color: 1b9421
description: Improvements or additions to documentation
- name: duplicate
color: cfd3d7
description: This issue or pull request already exists
- name: enhancement
color: a2eeef
description: New feature or request
- name: good first issue
color: 7057ff
description: Good for newcomers
- name: help wanted
color: 008672
description: Extra attention is needed
- name: invalid
color: e4e669
description: This doesn't seem right
- name: question
color: d876e3
description: Further information is requested
- name: wontfix
color: ffffff
description: This will not be worked on
# Custom
- name: dependencies
color: 0366d6
description: Pull request that update a dependency file
- name: actions
color: 0366d6
description: Pull request that update a action
- name: docker
color: 0366d6
description: Pull request that update a Dockerfile
branches:
- name: master
protection:
required_pull_request_reviews:
required_approving_review_count: 1
dismiss_stale_reviews: true
require_code_owner_reviews: false
dismissal_restrictions:
users: []
teams: []
required_status_checks:
strict: true
contexts: [ "sample" ]
enforce_admins: true
required_linear_history: true
restrictions:
apps: []
users: []
teams: []

View file

@ -0,0 +1,65 @@
---
name: "Molecule"
on:
schedule:
- cron: "0 21 * * *"
push:
branches:
- develop
pull_request:
types:
- main
- master
workflow_dispatch:
jobs:
lint:
name: "Ansible: Lint"
runs-on: ubuntu-latest
steps:
- name: "Init: Run checkout@v2"
uses: actions/checkout@v2
- name: "Ansible: Lint role"
uses: ansible/ansible-lint-action@master
with:
targets: "./"
molecule:
name: "Molecule: Test"
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
images:
- "centos7"
- "centos8"
- "debian9"
- "debian10"
- "debian11"
- "ubuntu1804"
- "ubuntu2004"
container:
image: ghcr.io/pandemonium1986/alpine313:nightly
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- ${{ github.workspace }}:/opt/workspace/${{ github.repository }}
env:
ANSIBLE_FORCE_COLOR: "1"
PY_COLORS: "1"
DKR_IMAGE: ${{ matrix.images }}
options: >-
--workdir /opt/workspace/${{ github.repository }}
needs:
- lint
steps:
- name: "Init: Run checkout@v2"
uses: actions/checkout@v2
- name: "Molecule: Create"
run: molecule create
- name: "Molecule: Converge"
run: molecule converge
- name: "Molecule: Idempotence"
run: molecule idempotence
- name: "Molecule: Verify"
run: molecule verify
- name: "Molecule: Destroy"
run: molecule destroy

View file

@ -0,0 +1,18 @@
# Created by https://www.gitignore.io/api/ansible,vagrant
### Ansible ###
*.retry
ansible-provisioner/roles/
### Vagrant ###
# General
.vagrant/
# Log files (if you are creating logs in debug mode, uncomment this)
# *.logs
### Vagrant Patch ###
*.box
# End of https://www.gitignore.io/api/ansible,vagrant

View file

@ -0,0 +1,55 @@
---
extends: default
rules:
braces:
level: error
min-spaces-inside: 1
max-spaces-inside: 1
min-spaces-inside-empty: 0
max-spaces-inside-empty: 0
brackets:
level: error
min-spaces-inside: 1
max-spaces-inside: 1
min-spaces-inside-empty: 0
max-spaces-inside-empty: 0
colons:
level: error
max-spaces-before: 0
max-spaces-after: -1
commas:
level: error
max-spaces-before: 0
min-spaces-after: 1
max-spaces-after: 1
comments:
level: warning
require-starting-space: true
min-spaces-from-content: 1
comments-indentation:
level: warning
document-start:
level: error
present: true
empty-lines:
level: error
max-start: 0
max-end: 1
max: 1
empty-values:
level: warning
hyphens:
level: error
max-spaces-after: 1
indentation:
level: warning
spaces: 2
indent-sequences: consistent
check-multi-line-strings: false
line-length: disable
# quoted-strings:
# level: warning
# quote-type: double

View file

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2021 Michael Maffait
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View file

@ -0,0 +1,56 @@
# Ansible role : k9s
* * *
**Disclaimer**
All contributions made directly in this repository will be deleted by force push. If you want to contribute, go to [ansible-collection-k8s-toolbox](https://github.com/Pandemonium1986/ansible-collection-k8s-toolbox)
* * *
![Ansible Role](https://img.shields.io/ansible/role/51049?logo=ansible)
![Github pipeline status](https://github.com/Pandemonium1986/ansible-role-k9s/workflows/Molecule:%20Github%20actions%20pipeline/badge.svg)
![GitHub release](https://img.shields.io/github/release/Pandemonium1986/ansible-role-k9s.svg?logo=github)
![Github license](https://img.shields.io/github/license/Pandemonium1986/ansible-role-k9s.svg?logo=github)
![Ansible Quality Score](https://img.shields.io/ansible/quality/51049?logo=ansible)
Install and configure k9s from github repository.
## Requirements
This role is self contained and install k9s for debian, ubuntu, linux mint, centos.
## Role Variables
From defaults/main.yml :
```yaml
k9s_cache_path: "/var/cache/github"
k9s_installation_path: "/opt/github/k9s"
k9s_checksum: "sha256:42d8aef6b839a9bc60de29d2461521596ce2d1f66347dbf5196983229cfeafd2"
k9s_version: "v0.22.1"
```
## Example Playbook
```yaml
- name: k9s installation
hosts: all
become: true
tasks:
- import_role:
name: pandemonium1986.k9s
```
## Versioning
We use [SemVer](http://semver.org/) for versioning. For the versions available, see the [tags on this repository](https://github.com/Pandemonium1986/ansible-role-k9s/tags).
## Authors
- **Michael Maffait** - _Initial work_ - [Pandemonium1986](https://github.com/Pandemonium1986)
See also the list of [contributors](https://github.com/your/project/contributors) who participated in this project.
## License
This project is licensed under the MIT License - see the [LICENSE](./LICENSE) file for details

View file

@ -1,4 +1,6 @@
---
k9s_cache_path: "/var/cache/github"
# https://github.com/derailed/k9s
k9s_cache_path: "/var/cache/github"
k9s_installation_path: "/opt/github/k9s"
k9s_version: "v0.24.15"
k9s_checksum: "sha256:b0eb5fb0decedbee5b6bd415f72af8ce6135ffb8128f9709bc7adcd5cbfa690b"
k9s_version: "v0.27.3"

View file

@ -0,0 +1,18 @@
---
galaxy_info:
role_name: k9s
author: Michael Maffait
description: Install k9s from github repository.
# company: your company (optional)
license: MIT
min_ansible_version: 2.9
github_branch: master
platforms:
- name: Debian
versions: [ 'stretch', 'buster' ]
- name: EL
versions: [ '7', '8' ]
- name: Ubuntu
versions: [ 'bionic' ]
galaxy_tags: [ 'kubernetes', 'tool', 'k8s' ]
dependencies: []

View file

@ -0,0 +1,7 @@
---
- name: Converge
hosts: all
tasks:
- name: "Include ansible-role-k9s"
include_role:
name: "ansible-role-k9s"

View file

@ -0,0 +1,36 @@
---
dependency:
name: galaxy
enabled: false
# role-file: requirements.yml
driver:
name: docker
lint: |
set -e
yamllint .
ansible-lint
platforms:
- name: molecule-${DKR_IMAGE:-debian10}
hostname: ${DKR_IMAGE:-debian10}
image: ghcr.io/pandemonium1986/${DKR_IMAGE:-debian10}:nightly
pull: true
pre_build_image: true
tty: true
override_command: false
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
privileged: true
provisioner:
name: ansible
lint: |
set -e
ansible-lint
config_options:
defaults:
stdout_callback: yaml
bin_ansible_callbacks: true
scenario:
name: default
verifier:
name: ansible
enabled: true

View file

@ -0,0 +1,19 @@
---
- name: Prepare
hosts: all
vars:
users: [ "pandemonium" ]
tasks:
- name: Ensure sudo is installed on all platforms
package:
name: [ sudo ]
state: present
- name: Create molecule user
user:
name: "{{ item }}"
generate_ssh_key: true
ssh_key_bits: 4096
ssh_key_comment: fake_key
ssh_key_file: .ssh/id_rsa
ssh_key_type: rsa
loop: "{{ users }}"

View file

@ -0,0 +1,45 @@
---
- name: Verify
hosts: all
gather_facts: true
tasks:
- name: Run k9s as a privileged user
block:
- name: Am I privileged ?
command:
cmd: whoami
register: whoami_result_priv
ignore_errors: true
- name: Run k9s (privileged user)
command:
cmd: /usr/local/bin/k9s version -s
register: k9s_result_priv
ignore_errors: true
- name: Ensure k9s is installed and running (privileged user)
assert:
that:
- k9s_result_priv.rc == 0
fail_msg: "k9s does not seem to be available for the user {{ whoami_result_priv.stdout }}"
success_msg: "k9s is available for the user {{ whoami_result_priv.stdout }} : {{ k9s_result_priv.stdout }}"
become: true
become_user: root
- name: Run k9s as a non-privileged user
block:
- name: Am I without privilege ?
command:
cmd: whoami
register: whoami_result_nopriv
ignore_errors: true
- name: Run k9s (non-privileged user)
command:
cmd: /usr/local/bin/k9s version -s
register: k9s_result_nopriv
ignore_errors: true
- name: Ensure k9s is installed and running (non-privileged user)
assert:
that:
- k9s_result_nopriv.rc == 0
fail_msg: "k9s does not seem to be available for the user {{ whoami_result_nopriv.stdout }}"
success_msg: "k9s is available for the user {{ whoami_result_nopriv.stdout }} : {{ k9s_result_nopriv.stdout }}"
become: true
become_user: pandemonium

View file

@ -1,28 +1,29 @@
---
- name: Ensure k9s directories are created
file:
path: "{{ item }}"
state: directory
mode: "0755"
loop:
- "{{ k9s_cache_path }}"
- "{{ k9s_installation_path }}"
- name: Ensure k9s directories are created
file:
path: "{{ item }}"
state: directory
mode: "0755"
loop:
- "{{ k9s_cache_path }}"
- "{{ k9s_installation_path }}"
- name: Ensure k9s is installed
get_url:
url: "{{ source_url }}/{{ github_namespace }}/releases/download/{{ k9s_version }}/{{ asset_name }}"
dest: "{{ k9s_cache_path }}"
mode: "0755"
- name: Ensure k9s is installed
get_url:
url: "{{ source_url }}/{{ github_namespace }}/releases/download/{{ k9s_version }}/{{ asset_name }}"
dest: "{{ k9s_cache_path }}"
checksum: "{{ k9s_checksum }}"
mode: "0755"
- name: Unarchive k9s archive into k9s_installation_path
unarchive:
src: "{{ k9s_cache_path }}/{{ asset_name }}"
dest: "{{ k9s_installation_path }}"
remote_src: true
mode: "0755"
- name: Unarchive k9s archive into k9s_installation_path
unarchive:
src: "{{ k9s_cache_path }}/{{ asset_name }}"
dest: "{{ k9s_installation_path }}"
remote_src: true
mode: "0755"
- name: Ensure k9s link is created
file:
src: "{{ k9s_installation_path }}/{{ binary_name }}"
dest: "/usr/local/bin/{{ binary_name }}"
state: link
- name: Ensure k9s link is created
file:
src: "{{ k9s_installation_path }}/{{ binary_name }}"
dest: "/usr/local/bin/{{ binary_name }}"
state: link

View file

@ -0,0 +1 @@
localhost

View file

@ -0,0 +1,5 @@
---
- hosts: localhost
remote_user: root
roles:
- ansible-role-k9s

View file

@ -1,5 +1,5 @@
---
source_url: "https://github.com"
source_url: "https://github.com"
github_namespace: "derailed/k9s"
asset_name: "k9s_Linux_x86_64.tar.gz"
binary_name: "k9s"
asset_name: "k9s_Linux_amd64.tar.gz"
binary_name: "k9s"