Skip to content

Commit

Permalink
Vagrant add private interface for host connection to service
Browse files Browse the repository at this point in the history
Vagrant increase resources due to issues
Configure microk8s using Ansible Kubernetes collection
Move Ansible tasks to roles
Ansible service checks and microk8s facts added
  • Loading branch information
Dean Taylor authored and Dean Taylor committed Feb 9, 2021
1 parent 7d73323 commit acfab46
Show file tree
Hide file tree
Showing 22 changed files with 548 additions and 171 deletions.
10 changes: 8 additions & 2 deletions contrib/Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,24 @@ Vagrant.configure("2") do |config|
# https://docs.vagrantup.com.
config.vm.box = "ubuntu/focal64"
config.vm.hostname = "ais-dev"
#config.vm.network "private_network", type: "dhcp"
config.vm.network "private_network", type: "dhcp"
config.vm.synced_folder ".", "/vagrant", type: "virtualbox"

config.vm.provider "virtualbox" do |vb|
vb.cpus = 4
vb.memory = "2048"
vb.memory = "4096"
end

config.vm.provision "shell", inline: <<-SCRIPT
COLLECTIONS_PATH='/usr/share/ansible/collections'
FACTS_D='/etc/ansible/facts.d'
REQUIREMENTS_YML='/vagrant/ansible/requirements.yml'
apt-get update
apt-get -y install ansible
set -x
[ -f $REQUIREMENTS_YML ] && \
ansible-galaxy collection install --collections-path $COLLECTIONS_PATH -r $REQUIREMENTS_YML && \
chown -R vagrant:vagrant $COLLECTIONS_PATH
if ! [ -f ${FACTS_D}/vagrant.fact ]; then
mkdir -p "${FACTS_D}"
cat <<EOT >${FACTS_D}/vagrant.fact
Expand Down
171 changes: 3 additions & 168 deletions contrib/ansible/development.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,171 +2,6 @@
# development.yaml
# Run using `ansible-playbook -clocal localhost development.yaml`
- hosts: all
tasks:
- name: essential tools
package:
name: "{{ item }}"
with_items:
- git
- gpg
- jq
- make
- python3-pip
become: yes
- name: python modules
become: yes
pip:
name:
- yq
- name: microk8s
become: yes
block:
- name: microk8s install
snap:
name: microk8s
channel: 1.19/stable
classic: yes
- name: kubectl and helm3 install
snap:
name: "{{ item }}"
state: present
classic: yes
with_items:
- kubectl
- helm
- name: microk8s group membership
user:
name: "{{ item }}"
append: yes
groups: microk8s
with_items:
- "{{ 'ubuntu' if not ansible_local.vagrant.default.user else ansible_local.vagrant.default.user }}"
- name: KUBECONFIG kubectl setup
copy:
content: |
DIR="${HOME}/.kube"
if which kubectl &>/dev/null; then
[ -d "${DIR}" ] || mkdir -p "${DIR}"
if ! [ -f "${DIR}/microk8s.config" ]; then
which microk8s &>/dev/null && \
microk8s config | sed 's/\(user\|name\): admin/\1: microk8s-admin/' > "${DIR}/microk8s.config"
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: microk8s FACTS
copy:
content: |
#!/usr/bin/env bash
microk8s status --format yaml | yq
dest: /etc/ansible/facts.d/microk8s.fact
mode: 0755
register: microk8s_facts
- name: FACTS reload
ansible.builtin.setup:
filter: ansible_local
when: microk8s_facts.changed
- name: microk8s enable features
command: microk8s enable {{ item }}
with_items:
- ha-cluster
- dns
- ingress
- rbac
- registry
- storage
when: (ansible_local.microk8s.addons | selectattr('name','contains', item ) | first).status == "disabled"
- name: Docker engine install
become: yes
block:
- name: Docker prereq.
package:
name: "{{ item }}"
with_items:
- apt-transport-https
- ca-certificates
- curl
- gnupg-agent
- software-properties-common
- name: Docker GPG key
apt_key:
id: 0EBFCD88
state: present
url: https://download.docker.com/linux/ubuntu/gpg
- name: Docker repository
apt_repository:
repo: >
deb
[arch={{ ansible_architecture|replace('x86_64','amd64') }}]
https://download.docker.com/linux/ubuntu
{{ ansible_distribution_release }}
stable
state: present
update_cache: yes
- name: Docker install
package:
name: "{{ item }}"
with_items:
- docker-ce
- docker-ce-cli
- containerd.io
- name: Docker group membership
user:
append: yes
name: "{{ item }}"
groups: [ "docker" ]
with_items:
- "{{ 'ubuntu' if not ansible_local.vagrant.default.user else ansible_local.vagrant.default.user }}"
- name: Docker microk8s insecure-registries
copy:
content: |
{
"insecure-registries" : ["localhost:32000"]
}
dest: /etc/docker/daemon.json
register: docker_daemon_json
- name: restart Docker service
service:
name: docker
state: restarted
when: docker_daemon_json.changed
- name: Packer
become: yes
block:
- name: Packer apt-key
apt_key:
state: present
url: https://apt.releases.hashicorp.com/gpg
- name: HashiCorp repository
apt_repository:
repo: >
deb
[arch={{ ansible_architecture|replace('x86_64','amd64') }}]
https://apt.releases.hashicorp.com
{{ ansible_distribution_release }}
main
state: present
update_cache: yes
- name: Packer install
package:
name: packer
- name: SOPS
become: yes
block:
- name: SOPS download
get_url:
dest: "/usr/local/bin"
url: "https://github.com/mozilla/sops/releases/download/v3.6.1/sops-v3.6.1.linux"
mode: 0755
- name: SOPS symlink
file:
path: "/usr/local/bin/sops"
src: "/usr/local/bin/sops-v3.6.1.linux"
state: link
- name: git-secrets
become: yes
package:
name: git-secrets
state: latest
roles:
- k8s-dev
- k8s-cert-manager
5 changes: 5 additions & 0 deletions contrib/ansible/requirements.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
# ansible-galaxy install -r requirements.yml
collections:
- community.kubernetes
#- kubernetes.core
29 changes: 29 additions & 0 deletions contrib/ansible/roles/k8s-cert-manager/.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 contrib/ansible/roles/k8s-cert-manager/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).
2 changes: 2 additions & 0 deletions contrib/ansible/roles/k8s-cert-manager/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
# defaults file for k8s-cert-manager
2 changes: 2 additions & 0 deletions contrib/ansible/roles/k8s-cert-manager/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
# handlers file for k8s-cert-manager
57 changes: 57 additions & 0 deletions contrib/ansible/roles/k8s-cert-manager/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
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.9

# 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.

collections:
- community.kubernetes
#- kubernetes.core

Loading

0 comments on commit acfab46

Please sign in to comment.