Code development platform for open source projects from the European Union institutions :large_blue_circle: EU Login authentication by SMS has been phased out. To see alternatives please check here

Skip to content
Snippets Groups Projects
Commit 6eb39837 authored by Jean-François HOVINNE's avatar Jean-François HOVINNE
Browse files

ci: Add tests, fix code style (fixes #2)

parent 408fc135
No related branches found
No related tags found
1 merge request!2ci: Add tests, fix code style (fixes #2)
variables:
PROJECT_ID: ${CI_PROJECT_ID}
ROLE: ${CI_PROJECT_NAME}
BRANCH: ${CI_COMMIT_REF_NAME}
TAG: ${CI_COMMIT_TAG}
PUBLISH: "true"
test:
trigger:
project: ecgalaxy/tooling
strategy: depend
---
# Based on ansible-lint config
extends: default
rules:
braces:
max-spaces-inside: 1
level: error
brackets:
max-spaces-inside: 1
level: error
colons:
max-spaces-after: -1
level: error
commas:
max-spaces-after: -1
level: error
comments: disable
comments-indentation: disable
document-start: disable
empty-lines:
max: 3
level: error
hyphens:
level: error
indentation: disable
key-duplicates: enable
line-length: disable
new-line-at-end-of-file: disable
new-lines:
type: unix
trailing-spaces: disable
truthy: disable
ECGALAXY microk8s
===============
Ansible role that installs microk8s and addons.
Ansible role that installs [MicroK8s](https://microk8s.io/) and addons.
Requirements
------------
- Currently, only supported on Ubuntu 22.04 LTS.
- Ubuntu 22.04 LTS, which is the only platform currently supported.
- [Snap](https://snapcraft.io/).
Role Variables
--------------
......@@ -17,6 +18,7 @@ Role Variables
Dependencies
------------
None.
Example Playbook
......
---
galaxy_info:
author: ecgalaxy
description: Ansible role that installs microk8s and addons.
description: Ansible role that installs MicroK8s and addons
company: European Commission
license: EUPL-1.2
min_ansible_version: "2.5"
......@@ -10,5 +10,8 @@ galaxy_info:
versions:
- jammy
galaxy_tags:
- containers
- k8s
- kubernetes
- microk8s
dependencies: []
---
- name: Converge
hosts: all
tasks:
- name: Include microk8s
ansible.builtin.include_role:
name: microk8s
vars:
microk8s_user: 'microk8s_user'
environment:
http_proxy: "{{ lookup('env', 'http_proxy') }}"
https_proxy: "{{ lookup('env', 'https_proxy') }}"
no_proxy: "{{ lookup('env', 'no_proxy') }}"
---
dependency:
name: galaxy
driver:
name: docker
platforms:
- name: ubuntu2204-${CI_JOB_ID:-0}
image: code.europa.eu:4567/ecgalaxy/ubuntu2204-ansible:latest
command: ""
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup
- /sys/kernel/security:/sys/kernel/security
cgroupns_mode: host
privileged: true
pre_build_image: true
environment:
http_proxy: "${http_proxy}"
https_proxy: "${https_proxy}"
no_proxy: "${no_proxy}"
provisioner:
name: ansible
inventory:
group_vars:
all:
ansible_user: ansible
verifier:
name: ansible
lint: |
set -e
yamllint .
ansible-lint .
---
- name: Prepare
hosts: all
tasks:
- name: Update apt cache
ansible.builtin.apt:
update_cache: true
cache_valid_time: 600
when: ansible_os_family == 'Debian'
changed_when: false
- name: Install dependencies
ansible.builtin.package:
name:
- fuse
- snap
- snapd
- squashfuse
state: present
- name: Start snapd
ansible.builtin.systemd:
name: snapd
enabled: yes
state: started
environment:
http_proxy: "{{ lookup('env', 'http_proxy') }}"
https_proxy: "{{ lookup('env', 'https_proxy') }}"
no_proxy: "{{ lookup('env', 'no_proxy') }}"
become: true
---
- name: Verify
hosts: all
vars_files:
- ../../defaults/main.yml
tasks:
- name: Check microk8s execution
ansible.builtin.command: /snap/bin/microk8s version # noqa no-changed-when
register: output
become: true
- name: Assert return code is 0
ansible.builtin.assert:
that:
- output.rc == 0
---
- name: Assert microk8s_user is set
ansible.builtin.assert:
that:
......@@ -9,44 +8,54 @@
fail_msg: "The variable 'microk8s_user' has not been set."
success_msg: "'microk8s_user' is currently set to {{ microk8s_user }}"
- name: "Ensure that the user '{{ microk8s_user }}' exists."
become: true
- name: "Ensure that the following user exists: '{{ microk8s_user }}'"
ansible.builtin.user:
name: "{{ microk8s_user }}"
create_home: true
state: "present"
register: microk8s_user_info
become: true
- name: "Retrieve user home directory for user: '{{ microk8s_user }}'"
ansible.builtin.set_fact:
user_home_dir: "{{ microk8s_user_info.home }}"
- name: Install microk8s using snap
become: true
block:
- name: Install microk8s using snap
community.general.snap:
name: microk8s
classic: true
channel: "{{ microk8s_version }}"
become: true
- name: "Add user '{{ microk8s_user }}' to group microk8s"
rescue:
- name: Install microk8s using snap (rescue)
ansible.builtin.command: "snap install microk8s --classic --channel={{ microk8s_version }}"
become: true
register: cmd_result
changed_when: "'already installed' not in cmd_result.stdout"
failed_when: "'installed' not in cmd_result.stdout"
- name: "Add following user to group microk8s: '{{ microk8s_user }}'"
ansible.builtin.user:
name: "{{ microk8s_user }}"
groups: microk8s
become: true
- name: "Set ownership of $HOME/.kube caching directory"
become: true
ansible.builtin.file:
path: "{{ user_home_dir }}/.kube"
recurse: true
owner: "{{ microk8s_user }}"
group: "{{ microk8s_user }}"
state: directory
become: true
- name: Enable addons in microk8s
become: true
ansible.builtin.command:
cmd: microk8s enable {{ item }}
loop: "{{ microk8s_addons }}"
register: enable_output
changed_when: "'already enabled' not in enable_output.stdout"
become: true
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment