Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
dean-taylor committed May 3, 2021
0 parents commit 9c0e032
Show file tree
Hide file tree
Showing 13 changed files with 239 additions and 0 deletions.
29 changes: 29 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
language: python
python: "2.7"

# Use the new container infrastructure
sudo: false

# Install ansible
addons:
apt:
packages:
- python-pip

install:
# Install ansible
- pip install ansible

# Check ansible version
- ansible --version

# Create ansible.cfg with correct roles_path
- printf '[defaults]\nroles_path=../' >ansible.cfg

script:
# Basic role syntax check
- ansible-playbook tests/test.yml -i tests/inventory --syntax-check

notifications:
webhooks: https://galaxy.ansible.com/api/v1/notifications/
38 changes: 38 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
Role Name
=========

A brief description of the role goes here.

Requirements
------------

Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required.

Role Variables
--------------

A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well.

Dependencies
------------

A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles.

Example Playbook
----------------

Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too:

- hosts: servers
roles:
- { role: username.rolename, x: 42 }

License
-------

BSD

Author Information
------------------

An optional section for the role authors to include contact information, or a website (HTML is not allowed).
12 changes: 12 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
# defaults file for microk8s
microk8s_snap_channel: 1.19/stable
microk8s_group_members: []
# - "{{ ansible_user_id }}"
microk8s_features:
- ha-cluster
- dns
- ingress
- rbac
- registry
- storage
2 changes: 2 additions & 0 deletions handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
# handlers file for microk8s
52 changes: 52 additions & 0 deletions meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
galaxy_info:
author: your name
description: your role description
company: your company (optional)

# If the issue tracker for your role is not on github, uncomment the
# next line and provide a value
# issue_tracker_url: http://example.com/issue/tracker

# Choose a valid license ID from https://spdx.org - some suggested licenses:
# - BSD-3-Clause (default)
# - MIT
# - GPL-2.0-or-later
# - GPL-3.0-only
# - Apache-2.0
# - CC-BY-4.0
license: license (GPL-2.0-or-later, MIT, etc)

min_ansible_version: 2.1

# If this a Container Enabled role, provide the minimum Ansible Container version.
# min_ansible_container_version:

#
# Provide a list of supported platforms, and for each platform a list of versions.
# If you don't wish to enumerate all versions for a particular platform, use 'all'.
# To view available platforms and versions (or releases), visit:
# https://galaxy.ansible.com/api/v1/platforms/
#
# platforms:
# - name: Fedora
# versions:
# - all
# - 25
# - name: SomePlatform
# versions:
# - all
# - 1.0
# - 7
# - 99.99

galaxy_tags: []
# List tags for your role here, one per line. A tag is a keyword that describes
# and categorizes the role. Users find roles by searching for tags. Be sure to
# remove the '[]' above, if you add tags to this list.
#
# NOTE: A tag is limited to a single word comprised of alphanumeric characters.
# Maximum 20 tags per role.

dependencies: []
# List your role dependencies here, one per line. Be sure to remove the '[]' above,
# if you add dependencies to this list.
2 changes: 2 additions & 0 deletions tasks/cert-manager.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---

8 changes: 8 additions & 0 deletions tasks/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
- name: microk8s enable features
ansible.builtin.command:
cmd: microk8s enable {{ item }}
with_items:
- "{{ microk8s_features }}"
when:
- ansible_local.microk8s.addons is defined
- (ansible_local.microk8s.addons | selectattr('name','contains', item ) | first).status == "disabled"
67 changes: 67 additions & 0 deletions tasks/install.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
---
# tasks file for microk8s
- name: install
community.general.snap:
channel: "{{ microk8s_snap_channel }}"
classic: yes
name: microk8s
state: present

- name: group membership
ansible.builtin.user:
append: yes
groups: microk8s
name: "{{ item }}"
with_items:
- "{{ ansible_user_id }}"
- "{{ microk8s_group_members }}"

- name: KUBECONFIG kubectl setup
ansible.builtin.copy:
content: |
DIR="${HOME}/.kube"
if which kubectl &>/dev/null; then
[ -d "${DIR}" ] || mkdir -p "${DIR}"
if ! [ -f "${DIR}/microk8s.config" ]; then
if which microk8s &>/dev/null; then
umask 0077
microk8s config | sed 's/\(user\|name\): admin/\1: microk8s-admin/' > "${DIR}/microk8s.config"
fi
fi
KUBECONFIG="$(find $DIR \( -name 'config' -o -name '*.config' \) \( -type f -o -type l \) -print0 | tr '\0' ':')"
KUBECONFIG="${KUBECONFIG%:}"
export KUBECONFIG
fi
dest: /etc/profile.d/KUBECONFIG.sh

- name: create ansible local facts directory
ansible.builtin.file:
path: /etc/ansible/facts.d
state: directory

- name: install local facts script
ansible.builtin.copy:
content: |
#!/usr/bin/env python3
import json
import subprocess
import yaml
try:
microk8sStatus = subprocess.run(["microk8s","status","--format yaml","--wait-ready","--timeout 60"], capture_output=True, timeout=10, check=True)
print(json.dumps(yaml.load(microk8sStatus.stdout, Loader=yaml.FullLoader)))
except:
print("{}")
dest: /etc/ansible/facts.d/microk8s.fact
mode: 0755
register: microk8s_facts

- name: wait for microk8s to start
ansible.builtin.shell:
cmd: microk8s status --format yaml --wait-ready --timeout 60
changed_when: false
register: microk8s_status

- name: reload ansible local facts
ansible.builtin.setup:
filter: ansible_local
when: microk8s_facts.changed
6 changes: 6 additions & 0 deletions tasks/join.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
- name: get microk8s join string
ansible.builtin.shell:
cmd: microk8s add-node
delegate_to: "{{ groups['microk8s'] | first }}"
register: microk8s_add_node
14 changes: 14 additions & 0 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
# tasks file for microk8s
- name: install
ansible.builtin.include_tasks: install.yml

- name: configure
ansible.builtin.include_tasks: config.yml
when:
- inventory_hostname == groups['microk8s'] | first

- name: join cluster
ansible.builtin.include_tasks: join.yml
when:
- inventory_hostname != groups['microk8s'] | first
2 changes: 2 additions & 0 deletions tests/inventory
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
localhost

5 changes: 5 additions & 0 deletions tests/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
- hosts: localhost
remote_user: root
roles:
- microk8s
2 changes: 2 additions & 0 deletions vars/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
# vars file for microk8s

0 comments on commit 9c0e032

Please sign in to comment.