Clark Boylan 60acea0da6 Run latest ansible-lint on Ubuntu Noble
We bump the Ansible version to the version that Zuul runs. We then set
ansible-lint to the current latest version. This results in a number of
new linter violations which we fix. These violations include:

 * Needing to name plays
 * Needing to start names with a capital letter
 * Using fully qualified names for action modules
 * Quoting permissions strings to avoid octal conversion errors
 * Using explicit yaml structures for tasks

We also tell ansible-lint to mock zuul_return so that we don't get
errors from it complaining that this module is not defined.

Change-Id: Ic881313fea58f4482f70e493f3d256541d31860a
2024-10-07 12:36:32 -07:00

142 lines
4.8 KiB
YAML

- name: Take screenshots of project-config grafana graphs
hosts: all
tasks:
- name: Install docker
include_role:
name: ensure-docker
# NOTE: keep after ensure-docker
- name: Use buildset registry
include_role:
name: use-buildset-registry
- name: Make environment vars
set_fact:
SECRETS_DIR: '{{ ansible_user_dir }}/grafana-secrets' # noqa: var-naming[pattern]
GRAFYAML_DIR: "{{ ansible_user_dir }}/{{ zuul.projects['opendev.org/openstack/project-config'].src_dir }}/grafana" # noqa: var-naming[pattern]
SCREENSHOTS: '{{ ansible_user_dir }}/screenshots' # noqa: var-naming[pattern]
# NOTE(ianw) : screenshots are 1920 x this height. This means
# it is about the right width to see easily. 5000 is a
# generic compromise; a bit long for some graphs, but it's
# just a solid black that compresses well in the .pngs. If
# required we can key each graph to individual heights with a
# config file or something some other time.
SCREENSHOT_HEIGHT: '5000' # noqa: var-naming[pattern]
# Initial sanity check
- name: Explicitly validate dashboards
shell:
executable: /bin/bash
cmd: |
docker run --rm -t -v {{ GRAFYAML_DIR }}:/grafana:ro \
--entrypoint /usr/local/bin/grafana-dashboard \
docker.io/opendevorg/grafyaml --debug validate /grafana
- name: Install pip
include_role:
name: ensure-pip
- name: Install dependencies
package:
name:
- python3-docker
state: present
become: yes
- name: Setup test environment
shell:
executable: /bin/bash
cmd: |
set -x
mkdir -p {{ SCREENSHOTS }}
mkdir -p {{ SECRETS_DIR }}
echo "password" > {{ SECRETS_DIR }}/admin_password
echo "admin" > {{ SECRETS_DIR }}/admin_user
echo "key" > {{ SECRETS_DIR }}/secret_key
- name: Run grafana
become: true
community.docker.docker_container:
name: grafana-opendev_test
image: "docker.io/grafana/grafana-oss"
state: started
network_mode: host
volumes:
- '{{ SECRETS_DIR }}:/etc/grafana/secrets'
env:
GF_AUTH_ANONYMOUS_ENABLED: 'true'
GF_USER_ALLOW_SIGN_UP: 'false'
GF_SECURITY_ADMIN_PASSWORD__FILE: /etc/grafana/secrets/admin_password
GF_SECURITY_ADMIN_USER__FILE: /etc/grafana/secrets/admin_user
GF_SECURITY_SECRET_KEY__FILE: /etc/grafana/secrets/secret_key
- name: Run selenium
become: true
community.docker.docker_container:
name: selenium-firefox
state: started
image: "docker.io/selenium/standalone-firefox"
# needs to talk to localhost
network_mode: host
- name: Install selenium bindings
pip:
name: selenium
virtualenv: '{{ ansible_user_dir }}/venv'
virtualenv_command: '{{ ensure_pip_virtualenv_command }}'
- name: Copy screenshot helper
copy:
src: 'screenshot.py'
dest: '{{ ansible_user_dir }}'
- name: Import dashboards
shell:
executable: /bin/bash
cmd: |
docker run --rm -t --network=host -e 'GRAFANA_URL=http://admin:password@localhost:3000' -v {{ GRAFYAML_DIR }}:/grafana:ro docker.io/opendevorg/grafyaml
- name: Get list of dashboards
uri:
url: 'http://localhost:3000/api/search'
method: GET
return_content: yes
validate_certs: false
status_code: 200
body_format: json
register: _dashboards
- name: List found dashboard URLs
debug:
msg: "{{ _dashboards.json | map(attribute='url') | list }}"
# NOTE(ianw) : Per the notes in the helper, this pauses for 5
# seconds for each shot to allow the app to initalize. I tried
# running this in parallel but it seemed to deadlock. I belive it
# has something to do with with the way selenium works with the
# headless browser. So it might be possible to speed up.
- name: Take screenshots
shell:
executable: /bin/bash
cmd: |
set -x
name=$(basename {{ item }})
url="http://localhost:3000{{ item }}"
{{ ansible_user_dir }}/venv/bin/python {{ ansible_user_dir }}/screenshot.py "{{ SCREENSHOTS }}/${name}.png" {{ SCREENSHOT_HEIGHT }} "${url}"
loop: "{{ _dashboards.json | map(attribute='url') | list }}"
- name: Copy output
ansible.posix.synchronize:
src: '{{ SCREENSHOTS }}'
dest: '{{ zuul.executor.log_root }}'
mode: pull
- name: Return screenshots artifact
zuul_return:
data:
zuul:
artifacts:
- name: Screenshots
url: "screenshots"