charm-zuul-jobs/playbooks/microk8s-cloud.yaml
Liam Young ebaa0b5d26 Add dockerhub caching proxy
Change-Id: I4a46da334867a9cdcf0d9a8f29d888f9a2dd32ed
2022-10-15 14:39:32 +00:00

117 lines
3.1 KiB
YAML

- hosts: all
name: Microk8s setup
roles:
- use-docker-mirror
tasks:
- name: snapd is installed
apt:
name: snapd
become: true
- name: microk8s is installed
snap:
name: microk8s
classic: true
become: true
- name: current user is in microk8s group
user:
name: "{{ ansible_user }}"
groups: microk8s
append: true
become: true
- name: reset ssh connection to apply permissions from new group
meta: reset_connection
- name: microk8s status
command:
cmd: microk8s status
- name: Create docker.io certs dir
when:
- docker_mirror is defined
file:
path: /var/snap/microk8s/current/args/certs.d/docker.io
state: directory
owner: root
group: microk8s
mode: '0770'
- name: Render microk8s registry mirror template
when:
- docker_mirror is defined
template:
src: hosts.j2
dest: /var/snap/microk8s/current/args/certs.d/docker.io/hosts.toml
group: microk8s
vars:
mirror_location: "{{ docker_mirror }}"
server: https://docker.io
- name: Check docker.io hosts.toml
when:
- docker_mirror is defined
command:
cmd: cat /var/snap/microk8s/current/args/certs.d/docker.io/hosts.toml
- name: microk8s is started
command:
cmd: microk8s start
- name: microk8s is running and ready
command:
cmd: microk8s status --wait-ready
register: res
failed_when: '"is running" not in res.stdout'
- name: microk8s dns addon is enabled
command:
cmd: microk8s enable dns
register: res
changed_when: '"already enabled" not in res.stdout'
- name: microk8s hostpath storage addon is enabled
command:
cmd: microk8s enable hostpath-storage
register: res
changed_when: '"already enabled" not in res.stdout'
- name: microk8s metallb addon is enabled
command:
# ip range is an arbitrary choice; may need to be changed later
cmd: microk8s enable metallb:10.170.0.1-10.170.0.100
register: res
changed_when: '"already enabled" not in res.stdout'
- name: microk8s addons are ready
command:
cmd: microk8s status --format short
register: res
retries: 18
delay: 10 # 18 * 10 = 3 minutes
until: >
"core/dns: enabled" in res.stdout and
"core/hostpath-storage: enabled" in res.stdout and
"core/metallb: enabled" in res.stdout
changed_when: res.attempts > 1
- name: juju is installed
snap:
name: juju
classic: true
become: true
- name: juju is bootstrapped on microk8s
command:
cmd: juju bootstrap microk8s microk8s
register: res
changed_when: '"already exists" not in res.stderr'
failed_when: '"ERROR" in res.stderr and "already exists" not in res.stderr'
- name: current juju controller is microk8s
command:
cmd: juju switch microk8s
register: res
changed_when: '"no change" not in res.stderr'