Reorganise into roles

Reorganise the ansible config into distinct roles. This will
make managing templates and default variables cleaner. I have tested
this as best I can locally.

Change-Id: Ib0be8dde453064336fd2e69afe466f4d64956743
This commit is contained in:
Liam Young 2022-10-27 14:25:55 +00:00
parent 9d61fc94c3
commit 3c4120fc28
10 changed files with 281 additions and 285 deletions

View File

@ -1,76 +1,3 @@
- hosts: all
tasks:
- name: lxd apt packages are not present
apt:
name:
- lxd
- lxd-client
state: absent
purge: true
become: true
- name: snapd is installed
apt:
name: snapd
become: true
- name: lxd snap is installed
snap:
name: lxd
channel: latest/stable
become: true
- name: lxd is initialised
command: lxd init --auto
become: true
- name: current user is in lxd group
user:
name: "{{ ansible_user }}"
groups: lxd
append: true
become: true
- name: reset ssh connection to apply permissions from new group
meta: reset_connection
- name: charmcraft is installed
snap:
name: charmcraft
channel: latest/stable
classic: true
become: true
- name: charm is packed
command:
cmd: charmcraft --verbosity trace pack
chdir: "{{ zuul.project.src_dir }}"
- name: local charm is named consistently
command:
cmd: ./rename.sh
chdir: "{{ zuul.project.src_dir }}"
- name: Compress built charm
archive:
dest: "{{ zuul.project.src_dir }}/{{ charm_build_name }}.charm.gz"
path: "{{ zuul.project.src_dir }}/{{ charm_build_name }}.charm"
format: gz
- name: built charm is available in the zuul log root for auto artifact upload
fetch:
src: "{{ zuul.project.src_dir }}/{{ charm_build_name }}.charm.gz"
dest: "{{ zuul.executor.log_root }}/"
flat: true
become: true
- name: Upload artifacts
zuul_return:
data:
zuul:
artifacts:
- name: charm
url: "{{ charm_build_name }}.charm.gz"
metadata:
type: charm
roles:
- charmbuild

View File

@ -1,124 +0,0 @@
- 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
channel: "{{ juju_channel | default('latest/stable') }}"
become: true
- name: juju is bootstrapped on microk8s
command:
cmd: juju bootstrap --agent-version=2.9.34 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'
- name: Collect snap versions
command: snap list
register: snap_out
- name: Show snap versions
debug: msg="{{ snap_out.stdout }}"

View File

@ -1,56 +0,0 @@
- hosts: all
tasks:
- name: Create destination for logs
file:
path: "{{ zuul.project.src_dir }}/log"
state: directory
mode: 0755
- name: debug logs replay
args:
executable: /bin/bash
shell: |
set -o pipefail
MODEL="$(juju models --format=json | jq -r '.models[]["short-name"]' | grep '^zaza-')"
juju switch $MODEL
juju debug-log --replay > {{ zuul.project.src_dir }}/log/debug-hooks.txt
exit 0
- name: debug describe pods
args:
executable: /bin/bash
shell: |
set -o pipefail
MODEL="$(juju models --format=json | jq -r '.models[]["short-name"]' | grep '^zaza-')"
microk8s.kubectl describe -n $MODEL pods > {{ zuul.project.src_dir }}/log/describe-pods.txt
exit 0
- name: juju status
args:
executable: /bin/bash
shell: |
set -o pipefail
for model in $(juju models | grep zaza- | awk '{gsub(/\*?/,""); print $1}'); do
juju status -m $model > {{ zuul.project.src_dir }}/log/juju-status.$model.txt
juju status -m $model --format=yaml > {{ zuul.project.src_dir }}/log/juju-status.$model.yaml
done
- name: Collect var logs
args:
executable: /bin/bash
shell: |
set -o pipefail
MODEL_NAME=$(juju models --format=json | jq -r '.models[]["short-name"]' | grep '^zaza-')
UNITS=$(juju status --format oneline | awk '{print $2}' | sed -e 's!:!!' | grep -Ev '^$' | paste -s -d' ')
for UNIT_NAME in $UNITS; do
POD_NAME=$(echo $UNIT_NAME | sed -e 's!/!-!')
CONTAINERS=$(microk8s.kubectl get pods -n $MODEL_NAME $POD_NAME -o jsonpath='{.spec.containers[*].name}' | sed -e 's/charm //')
for CONTAINER in $CONTAINERS; do
juju ssh --container $CONTAINER -m $MODEL_NAME $UNIT_NAME "tar zcf /tmp/logs.tgz /var/log/"
juju scp --container $CONTAINER -m $MODEL_NAME $UNIT_NAME:/tmp/logs.tgz {{ zuul.project.src_dir }}/log/$POD_NAME-$CONTAINER.tgz
done
done
- name: fetch juju logs
synchronize:
dest: "{{ zuul.executor.log_root }}"
mode: pull
src: "{{ zuul.project.src_dir }}/log"
verify_host: true
owner: false
group: false

View File

@ -1,29 +1,6 @@
- hosts: all
tasks:
- name: test runner packages are installed
apt:
name:
- tox
- jq
- gzip
become: true
- name: built charm is present locally (artefact from previous job)
include_role:
name: download-artifact
vars:
download_artifact_api: "https://zuul.opendev.org/api/tenant/{{ zuul.tenant }}"
download_artifact_type: charm
download_artifact_pipeline: check
download_artifact_job: charmbuild
download_artifact_directory: "{{ zuul.project.src_dir }}"
- name: Gunzip built charm
command:
cmd: gunzip {{ charm_build_name }}.charm.gz
chdir: "{{ zuul.project.src_dir }}"
- name: run smoke tests
command:
cmd: tox -e func-smoke
chdir: "{{ zuul.project.src_dir }}"
roles:
- use-docker-mirror
- microk8s-cloud
- zaza-smoke-test
- collect-run-data

View File

@ -0,0 +1,73 @@
- name: lxd apt packages are not present
apt:
name:
- lxd
- lxd-client
state: absent
purge: true
become: true
- name: snapd is installed
apt:
name: snapd
become: true
- name: lxd snap is installed
snap:
name: lxd
channel: latest/stable
become: true
- name: lxd is initialised
command: lxd init --auto
become: true
- name: current user is in lxd group
user:
name: "{{ ansible_user }}"
groups: lxd
append: true
become: true
- name: reset ssh connection to apply permissions from new group
meta: reset_connection
- name: charmcraft is installed
snap:
name: charmcraft
channel: latest/stable
classic: true
become: true
- name: charm is packed
command:
cmd: charmcraft --verbosity trace pack
chdir: "{{ zuul.project.src_dir }}"
- name: local charm is named consistently
command:
cmd: ./rename.sh
chdir: "{{ zuul.project.src_dir }}"
- name: Compress built charm
archive:
dest: "{{ zuul.project.src_dir }}/{{ charm_build_name }}.charm.gz"
path: "{{ zuul.project.src_dir }}/{{ charm_build_name }}.charm"
format: gz
- name: built charm is available in the zuul log root for auto artifact upload
fetch:
src: "{{ zuul.project.src_dir }}/{{ charm_build_name }}.charm.gz"
dest: "{{ zuul.executor.log_root }}/"
flat: true
become: true
- name: Upload artifacts
zuul_return:
data:
zuul:
artifacts:
- name: charm
url: "{{ charm_build_name }}.charm.gz"
metadata:
type: charm

View File

@ -0,0 +1,54 @@
- name: Create destination for logs
file:
path: "{{ zuul.project.src_dir }}/log"
state: directory
mode: 0755
- name: debug logs replay
args:
executable: /bin/bash
shell: |
set -o pipefail
MODEL="$(juju models --format=json | jq -r '.models[]["short-name"]' | grep '^zaza-')"
juju switch $MODEL
juju debug-log --replay > {{ zuul.project.src_dir }}/log/debug-hooks.txt
exit 0
- name: debug describe pods
args:
executable: /bin/bash
shell: |
set -o pipefail
MODEL="$(juju models --format=json | jq -r '.models[]["short-name"]' | grep '^zaza-')"
microk8s.kubectl describe -n $MODEL pods > {{ zuul.project.src_dir }}/log/describe-pods.txt
exit 0
- name: juju status
args:
executable: /bin/bash
shell: |
set -o pipefail
for model in $(juju models | grep zaza- | awk '{gsub(/\*?/,""); print $1}'); do
juju status -m $model > {{ zuul.project.src_dir }}/log/juju-status.$model.txt
juju status -m $model --format=yaml > {{ zuul.project.src_dir }}/log/juju-status.$model.yaml
done
- name: Collect var logs
args:
executable: /bin/bash
shell: |
set -o pipefail
MODEL_NAME=$(juju models --format=json | jq -r '.models[]["short-name"]' | grep '^zaza-')
UNITS=$(juju status --format oneline | awk '{print $2}' | sed -e 's!:!!' | grep -Ev '^$' | paste -s -d' ')
for UNIT_NAME in $UNITS; do
POD_NAME=$(echo $UNIT_NAME | sed -e 's!/!-!')
CONTAINERS=$(microk8s.kubectl get pods -n $MODEL_NAME $POD_NAME -o jsonpath='{.spec.containers[*].name}' | sed -e 's/charm //')
for CONTAINER in $CONTAINERS; do
juju ssh --container $CONTAINER -m $MODEL_NAME $UNIT_NAME "tar zcf /tmp/logs.tgz /var/log/"
juju scp --container $CONTAINER -m $MODEL_NAME $UNIT_NAME:/tmp/logs.tgz {{ zuul.project.src_dir }}/log/$POD_NAME-$CONTAINER.tgz
done
done
- name: fetch juju logs
synchronize:
dest: "{{ zuul.executor.log_root }}"
mode: pull
src: "{{ zuul.project.src_dir }}/log"
verify_host: true
owner: false
group: false

View File

@ -0,0 +1,119 @@
- 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
channel: "{{ juju_channel | default('latest/stable') }}"
become: true
- name: juju is bootstrapped on microk8s
command:
cmd: juju bootstrap --agent-version=2.9.34 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'
- name: Collect snap versions
command: snap list
register: snap_out
- name: Show snap versions
debug: msg="{{ snap_out.stdout }}"

View File

@ -0,0 +1,27 @@
- name: test runner packages are installed
apt:
name:
- tox
- jq
- gzip
become: true
- name: built charm is present locally (artefact from previous job)
include_role:
name: download-artifact
vars:
download_artifact_api: "https://zuul.opendev.org/api/tenant/{{ zuul.tenant }}"
download_artifact_type: charm
download_artifact_pipeline: check
download_artifact_job: charmbuild
download_artifact_directory: "{{ zuul.project.src_dir }}"
- name: Gunzip built charm
command:
cmd: gunzip {{ charm_build_name }}.charm.gz
chdir: "{{ zuul.project.src_dir }}"
- name: run smoke tests
command:
cmd: tox -e func-smoke
chdir: "{{ zuul.project.src_dir }}"

View File

@ -3,11 +3,10 @@
run: playbooks/charmbuild.yaml
provides: charm
timeout: 3600
- job:
name: zaza-smoke-test
pre-run: playbooks/microk8s-cloud.yaml
run: playbooks/zaza-smoke-test.yaml
post-run: playbooks/microk8s-juju-post.yaml
requires: charm
dependencies:
- name: charmbuild