diff --git a/.config/ansible-lint.yml b/.config/ansible-lint.yml new file mode 100644 index 00000000..9cd26302 --- /dev/null +++ b/.config/ansible-lint.yml @@ -0,0 +1,2 @@ +--- +profile: production diff --git a/.config/molecule/config.yml b/.config/molecule/config.yml new file mode 100644 index 00000000..b03c8336 --- /dev/null +++ b/.config/molecule/config.yml @@ -0,0 +1,60 @@ +--- +dependency: + name: galaxy +driver: + name: docker +lint: | + set -e + yamllint -c ${YAMLLINT_CONFIG_FILE} . + ansible-lint +platforms: + - name: almalinux-8 + image: dokken/almalinux-8 + pre_build_image: true + privileged: true + cgroup_parent: docker.slice + command: /lib/systemd/systemd + - name: centos-7 + image: dokken/centos-7 + pre_build_image: true + privileged: true + cgroup_parent: docker.slice + command: /usr/lib/systemd/systemd + - name: centos-stream-8 + image: dokken/centos-stream-8 + pre_build_image: true + privileged: true + cgroup_parent: docker.slice + command: /lib/systemd/systemd + - name: debian-9 + image: dokken/debian-9 + pre_build_image: true + privileged: true + cgroup_parent: docker.slice + command: /lib/systemd/systemd + - name: debian-10 + image: dokken/debian-10 + pre_build_image: true + privileged: true + cgroup_parent: docker.slice + command: /lib/systemd/systemd + - name: debian-11 + image: dokken/debian-11 + pre_build_image: true + privileged: true + cgroup_parent: docker.slice + command: /lib/systemd/systemd + - name: fedora-30 + image: dokken/fedora-30 + pre_build_image: true + privileged: true + cgroup_parent: docker.slice + command: /lib/systemd/systemd + - name: ubuntu-18.04 + image: dokken/ubuntu-18.04 + pre_build_image: true + privileged: true + cgroup_parent: docker.slice + command: /lib/systemd/systemd +verifier: + name: testinfra diff --git a/.config/yamllint/config.yml b/.config/yamllint/config.yml new file mode 100644 index 00000000..14c60b8c --- /dev/null +++ b/.config/yamllint/config.yml @@ -0,0 +1,23 @@ +--- +extends: default + +rules: + braces: + max-spaces-inside: 1 + level: error + brackets: + max-spaces-inside: 1 + level: error + colons: + max-spaces-after: -1 + level: error + commas: + max-spaces-after: -1 + level: error + empty-lines: + max: 3 + level: error + hyphens: + level: error + line-length: + max: 160 diff --git a/.github/workflows/ansible-ci.yml b/.github/workflows/ansible-ci.yml new file mode 100644 index 00000000..1fcbe26c --- /dev/null +++ b/.github/workflows/ansible-ci.yml @@ -0,0 +1,98 @@ +--- +name: Ansible CI +on: [push, pull_request] + +env: + ANSIBLE_FORCE_COLOR: true + +jobs: + ansible-lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Lint collection + uses: ansible/ansible-lint-action@main + + discover-ansible-versions: + runs-on: ubuntu-latest + outputs: + versions: ${{ steps.supported-ansible-versions.outputs.result }} + steps: + - uses: actions/checkout@v3 + + - name: Get Ansible versions that the collection supports + id: supported-ansible-versions + uses: mikefarah/yq@master + with: + cmd: yq -o json -I=0 '.requires_ansible | split(",") | .[] |= sub("(.*)", "stable-${1}")' meta/runtime.yml + + ansible-test-sanity: + uses: ./.github/workflows/ansible-test-sanity.yml + needs: + - ansible-lint + - discover-ansible-versions + with: + ansible-core-versions: ${{ needs.discover-ansible-versions.outputs.versions }} + + discover-ansible-tests: + runs-on: ubuntu-latest + needs: ansible-lint + outputs: + molecule-tests: ${{ steps.set-molecule-tests.outputs.tests }} + integration-tests: ${{ steps.set-integration-tests.outputs.tests }} + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Get changed roles + id: changed-roles + uses: tj-actions/changed-files@v35 + with: + path: "roles" + diff_relative: "true" + files: "**" + dir_names: "true" + dir_names_max_depth: "1" + since_last_remote_commit: "true" + + - name: Discover role tests + if: steps.changed-roles.outputs.any_changed == 'true' + id: set-molecule-tests + run: | + echo tests="[`for role in ${{ steps.changed-roles.outputs.all_changed_and_modified_files }}; do + for test in $(find tests/integration/targets -maxdepth 1 -mindepth 1 -type d -iname "molecule-${role}-*" -printf "%f\n"); do + echo '{"test":\"'"${test}"'\","name":\"'"${test#*-}\"'"}'; + done + done | tr '\n' ',' | sed '$s/,$//'`]" >> $GITHUB_OUTPUT + + - name: Discover integration tests + id: set-integration-tests + run: | + echo tests="[`for test in $(find tests/integration/targets -maxdepth 1 -mindepth 1 -type d -not -iname "molecule-*" -printf "%f\n"); do + echo '{"test":\"'"${test}"'\","name":\"'"${test}\"'"}'; + done | tr '\n' ',' | sed '$s/,$//'`]" >> $GITHUB_OUTPUT + + ansible-test-molecule: + uses: ./.github/workflows/ansible-test-integration.yml + needs: + - discover-ansible-tests + - discover-ansible-versions + if: needs.discover-ansible-tests.outputs.molecule-tests != '[]' && + needs.discover-ansible-tests.outputs.molecule-tests != '' + with: + targets: ${{ needs.discover-ansible-tests.outputs.molecule-tests }} + ansible-core-versions: ${{ needs.discover-ansible-versions.outputs.versions }} + + ansible-test-integration: + uses: ./.github/workflows/ansible-test-integration.yml + needs: + - discover-ansible-tests + - discover-ansible-versions + if: + needs.discover-ansible-tests.outputs.integration-tests != '[]' && + needs.discover-ansible-tests.outputs.integration-tests != '' + with: + targets: ${{ needs.discover-ansible-tests.outputs.integration-tests }} + ansible-core-versions: ${{ needs.discover-ansible-versions.outputs.versions }} diff --git a/.github/workflows/ansible-lint.yml b/.github/workflows/ansible-lint.yml deleted file mode 100644 index 44d66580..00000000 --- a/.github/workflows/ansible-lint.yml +++ /dev/null @@ -1,18 +0,0 @@ ---- -name: Ansible Lint -on: [push, pull_request] - -env: - ANSIBLE_FORCE_COLOR: true - -jobs: - lint: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - - - name: Lint roles - uses: ansible/ansible-lint-action@main - with: - path: roles diff --git a/.github/workflows/ansible-test-integration.yml b/.github/workflows/ansible-test-integration.yml new file mode 100644 index 00000000..8295c747 --- /dev/null +++ b/.github/workflows/ansible-test-integration.yml @@ -0,0 +1,39 @@ +--- +name: Ansible Integration Test +on: + workflow_call: + inputs: + targets: + required: true + type: string + ansible-core-versions: + required: false + default: '["stable-2.14"]' + type: string + target-python-versions: + required: false + default: '["default"]' + type: string + +jobs: + ansible-test-integration: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + targets: ${{ fromJson(inputs.targets) }} + ansible-core-versions: ${{ fromJson(inputs.ansible-core-versions) }} + target-python-versions: ${{ fromJson(inputs.target-python-versions) }} + + name: "${{ matrix.targets.name }}-${{ matrix.ansible-core-versions }}" + steps: + - name: "Perform ${{ matrix.targets.test }} integration test with ansible-test" + uses: ansible-community/ansible-test-gh-action@release/v1 + with: + ansible-core-version: ${{ matrix.ansible-core-versions }} + target-python-version: ${{ matrix.target-python-versions }} + controller-python-version: auto + docker-image: "--docker-privileged" # Workaround because ansible-test action doesn't support setting privileged flag + testing-type: integration + target: ${{ matrix.targets.test }} + # coverage: never # https://github.com/ansible-community/ansible-test-gh-action/pull/50 diff --git a/.github/workflows/ansible-test-sanity.yml b/.github/workflows/ansible-test-sanity.yml new file mode 100644 index 00000000..dd04a3cb --- /dev/null +++ b/.github/workflows/ansible-test-sanity.yml @@ -0,0 +1,25 @@ +--- +name: Ansible Sanity Test +on: + workflow_call: + inputs: + ansible-core-versions: + required: false + default: '["stable-2.14"]' + type: string + +jobs: + ansible-test-sanity: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + ansible-core-versions: ${{ fromJson(inputs.ansible-core-versions) }} + + name: "sanity-${{ matrix.ansible-core-versions }}" + steps: + - name: "Perform sanity test with ansible-test" + uses: ansible-community/ansible-test-gh-action@release/v1 + with: + ansible-core-version: ${{ matrix.ansible-core-versions }} + testing-type: sanity diff --git a/galaxy.yml b/galaxy.yml index 4dd29a15..10639c6d 100644 --- a/galaxy.yml +++ b/galaxy.yml @@ -1,7 +1,7 @@ --- namespace: prometheus name: prometheus -version: 0.0.1 +version: 1.0.0 readme: README.md authors: diff --git a/meta/runtime.yml b/meta/runtime.yml index 2ee3c9fa..855b061f 100644 --- a/meta/runtime.yml +++ b/meta/runtime.yml @@ -1,2 +1,2 @@ --- -requires_ansible: '>=2.9.10' +requires_ansible: "2.9,2.10,2.11,2.12,2.13,2.14" diff --git a/roles/alertmanager/molecule/alternative/playbook.yml b/roles/alertmanager/molecule/alternative/converge.yml similarity index 96% rename from roles/alertmanager/molecule/alternative/playbook.yml rename to roles/alertmanager/molecule/alternative/converge.yml index 735334cb..59691dcb 100644 --- a/roles/alertmanager/molecule/alternative/playbook.yml +++ b/roles/alertmanager/molecule/alternative/converge.yml @@ -3,7 +3,7 @@ hosts: all any_errors_fatal: true roles: - - alertmanager + - prometheus.prometheus.alertmanager vars: alertmanager_binary_local_dir: '/tmp/alertmanager-linux-amd64' alertmanager_config_dir: /opt/am/etc diff --git a/roles/alertmanager/molecule/alternative/molecule.yml b/roles/alertmanager/molecule/alternative/molecule.yml index c03bcf2a..ed97d539 100644 --- a/roles/alertmanager/molecule/alternative/molecule.yml +++ b/roles/alertmanager/molecule/alternative/molecule.yml @@ -1,70 +1 @@ --- -dependency: - name: galaxy -driver: - name: docker -platforms: - - name: bionic - pre_build_image: true - image: quay.io/paulfantom/molecule-systemd:ubuntu-18.04 - docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}" - privileged: true - volumes: - - /sys/fs/cgroup:/sys/fs/cgroup:ro - - name: xenial - pre_build_image: true - image: quay.io/paulfantom/molecule-systemd:ubuntu-16.04 - docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}" - privileged: true - volumes: - - /sys/fs/cgroup:/sys/fs/cgroup:ro - - name: stretch - pre_build_image: true - image: quay.io/paulfantom/molecule-systemd:debian-9 - docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}" - privileged: true - volumes: - - /sys/fs/cgroup:/sys/fs/cgroup:ro - - name: buster - pre_build_image: true - image: quay.io/paulfantom/molecule-systemd:debian-10 - docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}" - privileged: true - volumes: - - /sys/fs/cgroup:/sys/fs/cgroup:ro - - name: centos7 - pre_build_image: true - image: quay.io/paulfantom/molecule-systemd:centos-7 - docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}" - privileged: true - volumes: - - /sys/fs/cgroup:/sys/fs/cgroup:ro - - name: centos8 - pre_build_image: true - image: quay.io/paulfantom/molecule-systemd:centos-8 - docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}" - privileged: true - volumes: - - /sys/fs/cgroup:/sys/fs/cgroup:ro - groups: - - python3 - - name: fedora - pre_build_image: true - image: quay.io/paulfantom/molecule-systemd:fedora-30 - docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}" - privileged: true - volumes: - - /sys/fs/cgroup:/sys/fs/cgroup:ro - groups: - - python3 -provisioner: - name: ansible - playbooks: - prepare: prepare.yml - converge: playbook.yml - inventory: - group_vars: - python3: - ansible_python_interpreter: /usr/bin/python3 -verifier: - name: testinfra diff --git a/roles/alertmanager/molecule/alternative/tests/test_alternative.py b/roles/alertmanager/molecule/alternative/tests/test_alternative.py index cb89958a..73c36889 100644 --- a/roles/alertmanager/molecule/alternative/tests/test_alternative.py +++ b/roles/alertmanager/molecule/alternative/tests/test_alternative.py @@ -1,6 +1,9 @@ -import pytest +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + import os import testinfra.utils.ansible_runner +import pytest testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') diff --git a/roles/alertmanager/molecule/default/playbook.yml b/roles/alertmanager/molecule/default/converge.yml similarity index 91% rename from roles/alertmanager/molecule/default/playbook.yml rename to roles/alertmanager/molecule/default/converge.yml index 19c31d9b..784a56a7 100644 --- a/roles/alertmanager/molecule/default/playbook.yml +++ b/roles/alertmanager/molecule/default/converge.yml @@ -3,7 +3,7 @@ hosts: all any_errors_fatal: true roles: - - alertmanager + - prometheus.prometheus.alertmanager vars: alertmanager_slack_api_url: "http://example.com" alertmanager_receivers: diff --git a/roles/alertmanager/molecule/default/molecule.yml b/roles/alertmanager/molecule/default/molecule.yml index c03bcf2a..ed97d539 100644 --- a/roles/alertmanager/molecule/default/molecule.yml +++ b/roles/alertmanager/molecule/default/molecule.yml @@ -1,70 +1 @@ --- -dependency: - name: galaxy -driver: - name: docker -platforms: - - name: bionic - pre_build_image: true - image: quay.io/paulfantom/molecule-systemd:ubuntu-18.04 - docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}" - privileged: true - volumes: - - /sys/fs/cgroup:/sys/fs/cgroup:ro - - name: xenial - pre_build_image: true - image: quay.io/paulfantom/molecule-systemd:ubuntu-16.04 - docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}" - privileged: true - volumes: - - /sys/fs/cgroup:/sys/fs/cgroup:ro - - name: stretch - pre_build_image: true - image: quay.io/paulfantom/molecule-systemd:debian-9 - docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}" - privileged: true - volumes: - - /sys/fs/cgroup:/sys/fs/cgroup:ro - - name: buster - pre_build_image: true - image: quay.io/paulfantom/molecule-systemd:debian-10 - docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}" - privileged: true - volumes: - - /sys/fs/cgroup:/sys/fs/cgroup:ro - - name: centos7 - pre_build_image: true - image: quay.io/paulfantom/molecule-systemd:centos-7 - docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}" - privileged: true - volumes: - - /sys/fs/cgroup:/sys/fs/cgroup:ro - - name: centos8 - pre_build_image: true - image: quay.io/paulfantom/molecule-systemd:centos-8 - docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}" - privileged: true - volumes: - - /sys/fs/cgroup:/sys/fs/cgroup:ro - groups: - - python3 - - name: fedora - pre_build_image: true - image: quay.io/paulfantom/molecule-systemd:fedora-30 - docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}" - privileged: true - volumes: - - /sys/fs/cgroup:/sys/fs/cgroup:ro - groups: - - python3 -provisioner: - name: ansible - playbooks: - prepare: prepare.yml - converge: playbook.yml - inventory: - group_vars: - python3: - ansible_python_interpreter: /usr/bin/python3 -verifier: - name: testinfra diff --git a/roles/alertmanager/molecule/default/prepare.yml b/roles/alertmanager/molecule/default/prepare.yml deleted file mode 100644 index 5358b3bd..00000000 --- a/roles/alertmanager/molecule/default/prepare.yml +++ /dev/null @@ -1,5 +0,0 @@ ---- -- name: Prepare - hosts: all - gather_facts: false - tasks: [] diff --git a/roles/alertmanager/molecule/default/tests/test_default.py b/roles/alertmanager/molecule/default/tests/test_default.py index a20396b6..19545003 100644 --- a/roles/alertmanager/molecule/default/tests/test_default.py +++ b/roles/alertmanager/molecule/default/tests/test_default.py @@ -1,6 +1,9 @@ -import pytest +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + import os import testinfra.utils.ansible_runner +import pytest testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') diff --git a/roles/alertmanager/molecule/latest/playbook.yml b/roles/alertmanager/molecule/latest/converge.yml similarity index 91% rename from roles/alertmanager/molecule/latest/playbook.yml rename to roles/alertmanager/molecule/latest/converge.yml index ab51d122..c503555f 100644 --- a/roles/alertmanager/molecule/latest/playbook.yml +++ b/roles/alertmanager/molecule/latest/converge.yml @@ -3,7 +3,7 @@ hosts: all any_errors_fatal: true roles: - - alertmanager + - prometheus.prometheus.alertmanager vars: alertmanager_version: latest alertmanager_slack_api_url: "http://example.com" diff --git a/roles/alertmanager/molecule/latest/molecule.yml b/roles/alertmanager/molecule/latest/molecule.yml index a5a9cebb..ed97d539 100644 --- a/roles/alertmanager/molecule/latest/molecule.yml +++ b/roles/alertmanager/molecule/latest/molecule.yml @@ -1,35 +1 @@ --- -dependency: - name: galaxy -driver: - name: docker -platforms: - - name: buster - pre_build_image: true - image: quay.io/paulfantom/molecule-systemd:debian-10 - docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}" - privileged: true - volumes: - - /sys/fs/cgroup:/sys/fs/cgroup:ro - - name: fedora - pre_build_image: true - image: quay.io/paulfantom/molecule-systemd:fedora-30 - docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}" - privileged: true - volumes: - - /sys/fs/cgroup:/sys/fs/cgroup:ro - groups: - - python3 -provisioner: - name: ansible - playbooks: - create: ../default/create.yml - prepare: ../default/prepare.yml - converge: playbook.yml - destroy: ../default/destroy.yml - inventory: - group_vars: - python3: - ansible_python_interpreter: /usr/bin/python3 -verifier: - name: testinfra diff --git a/roles/alertmanager/molecule/latest/tests/test_latest.py b/roles/alertmanager/molecule/latest/tests/test_latest.py index 360a4459..258c8fb2 100644 --- a/roles/alertmanager/molecule/latest/tests/test_latest.py +++ b/roles/alertmanager/molecule/latest/tests/test_latest.py @@ -1,6 +1,9 @@ -import pytest +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + import os import testinfra.utils.ansible_runner +import pytest testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') diff --git a/roles/alertmanager/tasks/install.yml b/roles/alertmanager/tasks/install.yml index d0a22be7..66002c46 100644 --- a/roles/alertmanager/tasks/install.yml +++ b/roles/alertmanager/tasks/install.yml @@ -33,7 +33,7 @@ - name: Download alertmanager binary to local folder become: false ansible.builtin.get_url: - url: "https://github.com/prometheus/alertmanager/releases/download/v{{ alertmanager_version }}/ + url: "https://github.com/prometheus/alertmanager/releases/download/v{{ alertmanager_version }}/\ alertmanager-{{ alertmanager_version }}.linux-{{ go_arch }}.tar.gz" dest: "/tmp/alertmanager-{{ alertmanager_version }}.linux-{{ go_arch }}.tar.gz" checksum: "sha256:{{ __alertmanager_checksum }}" diff --git a/roles/alertmanager/tasks/preflight.yml b/roles/alertmanager/tasks/preflight.yml index 8e022b21..f4296f49 100644 --- a/roles/alertmanager/tasks/preflight.yml +++ b/roles/alertmanager/tasks/preflight.yml @@ -17,39 +17,27 @@ alertmanager_systemd_version: "{{ __systemd_version.stdout_lines[0].split(' ')[-1] }}" - name: Discover latest version + ansible.builtin.set_fact: + alertmanager_version: "{{ (lookup('url', 'https://api.github.com/repos/prometheus/alertmanager/releases/latest', split_lines=False) | + from_json).get('tag_name') | replace('v', '') }}" + run_once: true + until: alertmanager_version is version('0.0.0', '>=') + retries: 10 when: - alertmanager_version == "latest" - alertmanager_binary_local_dir | length == 0 - block: - - - name: Get latest release - ansible.builtin.uri: - url: "https://api.github.com/repos/prometheus/alertmanager/releases/latest" - method: GET - return_content: true - status_code: 200 - body_format: json - user: "{{ lookup('env', 'GH_USER') | default(omit) }}" - password: "{{ lookup('env', 'GH_TOKEN') | default(omit) }}" - no_log: "{{ not lookup('env', 'MOLECULE_DEBUG') | bool }}" - register: _latest_release - until: _latest_release.status == 200 - retries: 5 - - - name: "Set alertmanager version to {{ _latest_release.json.tag_name[1:] }}" - ansible.builtin.set_fact: - alertmanager_version: "{{ _latest_release.json.tag_name[1:] }}" - alertmanager_checksum_url: "https://github.com/prometheus/alertmanager/releases/download/v{{ alertmanager_version }}/sha256sums.txt" - name: Get alertmanager binary checksum - delegate_to: localhost when: - alertmanager_binary_local_dir | length == 0 block: - name: "Get checksum list" ansible.builtin.set_fact: - __alertmanager_checksums: "{{ lookup('url', 'https://github.com/prometheus/alertmanager/releases/download/v' + alertmanager_version + '/sha256sums.txt', wantlist=True) | list }}" + __alertmanager_checksums: "{{ lookup('url', 'https://github.com/prometheus/alertmanager/releases/download/v' + alertmanager_version + + '/sha256sums.txt', wantlist=True) | list }}" run_once: true + until: __alertmanager_checksums is search('linux-' + go_arch + '.tar.gz') + retries: 10 - name: "Get checksum for {{ go_arch }}" ansible.builtin.set_fact: @@ -138,5 +126,6 @@ - name: "`alertmanager_child_routes` is no longer supported" ansible.builtin.fail: - msg: "Please move content of `alertmanager_child_routes` to `alertmanager_route.routes` as the former variable is deprecated and will be removed in future versions." + msg: "Please move content of `alertmanager_child_routes` to `alertmanager_route.routes` as the former variable is deprecated + and will be removed in future versions." when: alertmanager_child_routes is defined diff --git a/roles/blackbox_exporter/molecule/alternative/playbook.yml b/roles/blackbox_exporter/molecule/alternative/converge.yml similarity index 86% rename from roles/blackbox_exporter/molecule/alternative/playbook.yml rename to roles/blackbox_exporter/molecule/alternative/converge.yml index a93b8eb6..b265876a 100644 --- a/roles/blackbox_exporter/molecule/alternative/playbook.yml +++ b/roles/blackbox_exporter/molecule/alternative/converge.yml @@ -3,7 +3,7 @@ hosts: all any_errors_fatal: true roles: - - blackbox_exporter + - prometheus.prometheus.blackbox_exporter vars: blackbox_exporter_web_listen_address: "127.0.0.1:9000" blackbox_exporter_cli_flags: diff --git a/roles/blackbox_exporter/molecule/alternative/molecule.yml b/roles/blackbox_exporter/molecule/alternative/molecule.yml index c03bcf2a..ed97d539 100644 --- a/roles/blackbox_exporter/molecule/alternative/molecule.yml +++ b/roles/blackbox_exporter/molecule/alternative/molecule.yml @@ -1,70 +1 @@ --- -dependency: - name: galaxy -driver: - name: docker -platforms: - - name: bionic - pre_build_image: true - image: quay.io/paulfantom/molecule-systemd:ubuntu-18.04 - docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}" - privileged: true - volumes: - - /sys/fs/cgroup:/sys/fs/cgroup:ro - - name: xenial - pre_build_image: true - image: quay.io/paulfantom/molecule-systemd:ubuntu-16.04 - docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}" - privileged: true - volumes: - - /sys/fs/cgroup:/sys/fs/cgroup:ro - - name: stretch - pre_build_image: true - image: quay.io/paulfantom/molecule-systemd:debian-9 - docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}" - privileged: true - volumes: - - /sys/fs/cgroup:/sys/fs/cgroup:ro - - name: buster - pre_build_image: true - image: quay.io/paulfantom/molecule-systemd:debian-10 - docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}" - privileged: true - volumes: - - /sys/fs/cgroup:/sys/fs/cgroup:ro - - name: centos7 - pre_build_image: true - image: quay.io/paulfantom/molecule-systemd:centos-7 - docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}" - privileged: true - volumes: - - /sys/fs/cgroup:/sys/fs/cgroup:ro - - name: centos8 - pre_build_image: true - image: quay.io/paulfantom/molecule-systemd:centos-8 - docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}" - privileged: true - volumes: - - /sys/fs/cgroup:/sys/fs/cgroup:ro - groups: - - python3 - - name: fedora - pre_build_image: true - image: quay.io/paulfantom/molecule-systemd:fedora-30 - docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}" - privileged: true - volumes: - - /sys/fs/cgroup:/sys/fs/cgroup:ro - groups: - - python3 -provisioner: - name: ansible - playbooks: - prepare: prepare.yml - converge: playbook.yml - inventory: - group_vars: - python3: - ansible_python_interpreter: /usr/bin/python3 -verifier: - name: testinfra diff --git a/roles/blackbox_exporter/molecule/alternative/prepare.yml b/roles/blackbox_exporter/molecule/alternative/prepare.yml deleted file mode 100644 index 5358b3bd..00000000 --- a/roles/blackbox_exporter/molecule/alternative/prepare.yml +++ /dev/null @@ -1,5 +0,0 @@ ---- -- name: Prepare - hosts: all - gather_facts: false - tasks: [] diff --git a/roles/blackbox_exporter/molecule/alternative/tests/test_alternative.py b/roles/blackbox_exporter/molecule/alternative/tests/test_alternative.py index cda4cba6..94e5c66e 100644 --- a/roles/blackbox_exporter/molecule/alternative/tests/test_alternative.py +++ b/roles/blackbox_exporter/molecule/alternative/tests/test_alternative.py @@ -1,6 +1,9 @@ -import pytest +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + import os import testinfra.utils.ansible_runner +import pytest testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') diff --git a/roles/blackbox_exporter/molecule/default/playbook.yml b/roles/blackbox_exporter/molecule/default/converge.yml similarity index 59% rename from roles/blackbox_exporter/molecule/default/playbook.yml rename to roles/blackbox_exporter/molecule/default/converge.yml index a993c218..e4fc80e5 100644 --- a/roles/blackbox_exporter/molecule/default/playbook.yml +++ b/roles/blackbox_exporter/molecule/default/converge.yml @@ -3,4 +3,4 @@ hosts: all any_errors_fatal: true roles: - - blackbox_exporter + - prometheus.prometheus.blackbox_exporter diff --git a/roles/blackbox_exporter/molecule/default/molecule.yml b/roles/blackbox_exporter/molecule/default/molecule.yml index c03bcf2a..ed97d539 100644 --- a/roles/blackbox_exporter/molecule/default/molecule.yml +++ b/roles/blackbox_exporter/molecule/default/molecule.yml @@ -1,70 +1 @@ --- -dependency: - name: galaxy -driver: - name: docker -platforms: - - name: bionic - pre_build_image: true - image: quay.io/paulfantom/molecule-systemd:ubuntu-18.04 - docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}" - privileged: true - volumes: - - /sys/fs/cgroup:/sys/fs/cgroup:ro - - name: xenial - pre_build_image: true - image: quay.io/paulfantom/molecule-systemd:ubuntu-16.04 - docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}" - privileged: true - volumes: - - /sys/fs/cgroup:/sys/fs/cgroup:ro - - name: stretch - pre_build_image: true - image: quay.io/paulfantom/molecule-systemd:debian-9 - docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}" - privileged: true - volumes: - - /sys/fs/cgroup:/sys/fs/cgroup:ro - - name: buster - pre_build_image: true - image: quay.io/paulfantom/molecule-systemd:debian-10 - docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}" - privileged: true - volumes: - - /sys/fs/cgroup:/sys/fs/cgroup:ro - - name: centos7 - pre_build_image: true - image: quay.io/paulfantom/molecule-systemd:centos-7 - docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}" - privileged: true - volumes: - - /sys/fs/cgroup:/sys/fs/cgroup:ro - - name: centos8 - pre_build_image: true - image: quay.io/paulfantom/molecule-systemd:centos-8 - docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}" - privileged: true - volumes: - - /sys/fs/cgroup:/sys/fs/cgroup:ro - groups: - - python3 - - name: fedora - pre_build_image: true - image: quay.io/paulfantom/molecule-systemd:fedora-30 - docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}" - privileged: true - volumes: - - /sys/fs/cgroup:/sys/fs/cgroup:ro - groups: - - python3 -provisioner: - name: ansible - playbooks: - prepare: prepare.yml - converge: playbook.yml - inventory: - group_vars: - python3: - ansible_python_interpreter: /usr/bin/python3 -verifier: - name: testinfra diff --git a/roles/blackbox_exporter/molecule/default/prepare.yml b/roles/blackbox_exporter/molecule/default/prepare.yml deleted file mode 100644 index 5358b3bd..00000000 --- a/roles/blackbox_exporter/molecule/default/prepare.yml +++ /dev/null @@ -1,5 +0,0 @@ ---- -- name: Prepare - hosts: all - gather_facts: false - tasks: [] diff --git a/roles/blackbox_exporter/molecule/default/tests/test_default.py b/roles/blackbox_exporter/molecule/default/tests/test_default.py index 4c6f1e3c..14bb00c6 100644 --- a/roles/blackbox_exporter/molecule/default/tests/test_default.py +++ b/roles/blackbox_exporter/molecule/default/tests/test_default.py @@ -1,6 +1,9 @@ -import pytest +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + import os import testinfra.utils.ansible_runner +import pytest testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') diff --git a/roles/blackbox_exporter/tasks/install.yml b/roles/blackbox_exporter/tasks/install.yml index 6ce7c217..0a362b3c 100644 --- a/roles/blackbox_exporter/tasks/install.yml +++ b/roles/blackbox_exporter/tasks/install.yml @@ -16,11 +16,11 @@ - name: Download blackbox exporter binary to local folder become: false ansible.builtin.unarchive: - src: "https://github.com/prometheus/blackbox_exporter/releases/download/v{{ blackbox_exporter_version }}/ + src: "https://github.com/prometheus/blackbox_exporter/releases/download/v{{ blackbox_exporter_version }}/\ blackbox_exporter-{{ blackbox_exporter_version }}.linux-{{ go_arch_map[ansible_architecture] | default(ansible_architecture) }}.tar.gz" dest: "/tmp" remote_src: true - creates: "/tmp/blackbox_exporter-{{ blackbox_exporter_version }}.linux-{{ go_arch_map[ansible_architecture] | default(ansible_architecture) }}/ + creates: "/tmp/blackbox_exporter-{{ blackbox_exporter_version }}.linux-{{ go_arch_map[ansible_architecture] | default(ansible_architecture) }}/\ blackbox_exporter" register: _download_binary until: _download_binary is succeeded @@ -31,7 +31,7 @@ - name: Propagate blackbox exporter binary ansible.builtin.copy: - src: "/tmp/blackbox_exporter-{{ blackbox_exporter_version }}.linux-{{ go_arch_map[ansible_architecture] | default(ansible_architecture) }}/ + src: "/tmp/blackbox_exporter-{{ blackbox_exporter_version }}.linux-{{ go_arch_map[ansible_architecture] | default(ansible_architecture) }}/\ blackbox_exporter" dest: "/usr/local/bin/blackbox_exporter" mode: 0750 @@ -56,6 +56,7 @@ capability: cap_net_raw+ep state: present when: not ansible_check_mode + changed_when: "'molecule-idempotence-notest' not in ansible_skip_tags" - name: Check Debug Message ansible.builtin.debug: diff --git a/roles/node_exporter/molecule/alternative/playbook.yml b/roles/node_exporter/molecule/alternative/converge.yml similarity index 90% rename from roles/node_exporter/molecule/alternative/playbook.yml rename to roles/node_exporter/molecule/alternative/converge.yml index 1af175de..809d23d2 100644 --- a/roles/node_exporter/molecule/alternative/playbook.yml +++ b/roles/node_exporter/molecule/alternative/converge.yml @@ -3,7 +3,7 @@ hosts: all any_errors_fatal: true roles: - - node_exporter + - prometheus.prometheus.node_exporter pre_tasks: - name: Create node_exporter cert dir ansible.builtin.file: @@ -11,13 +11,13 @@ state: directory owner: root group: root - mode: 0755 + mode: u+rwX,g+rwX,o=rX - name: Copy cert and key ansible.builtin.copy: src: "{{ item.src }}" dest: "{{ item.dest }}" - mode: "{{ item.mode | default(0644) }}" + mode: "{{ item.mode | default('0644') }}" loop: - src: "/tmp/tls.cert" dest: "{{ node_exporter_tls_server_config.cert_file }}" diff --git a/roles/node_exporter/molecule/alternative/molecule.yml b/roles/node_exporter/molecule/alternative/molecule.yml index c03bcf2a..ed97d539 100644 --- a/roles/node_exporter/molecule/alternative/molecule.yml +++ b/roles/node_exporter/molecule/alternative/molecule.yml @@ -1,70 +1 @@ --- -dependency: - name: galaxy -driver: - name: docker -platforms: - - name: bionic - pre_build_image: true - image: quay.io/paulfantom/molecule-systemd:ubuntu-18.04 - docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}" - privileged: true - volumes: - - /sys/fs/cgroup:/sys/fs/cgroup:ro - - name: xenial - pre_build_image: true - image: quay.io/paulfantom/molecule-systemd:ubuntu-16.04 - docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}" - privileged: true - volumes: - - /sys/fs/cgroup:/sys/fs/cgroup:ro - - name: stretch - pre_build_image: true - image: quay.io/paulfantom/molecule-systemd:debian-9 - docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}" - privileged: true - volumes: - - /sys/fs/cgroup:/sys/fs/cgroup:ro - - name: buster - pre_build_image: true - image: quay.io/paulfantom/molecule-systemd:debian-10 - docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}" - privileged: true - volumes: - - /sys/fs/cgroup:/sys/fs/cgroup:ro - - name: centos7 - pre_build_image: true - image: quay.io/paulfantom/molecule-systemd:centos-7 - docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}" - privileged: true - volumes: - - /sys/fs/cgroup:/sys/fs/cgroup:ro - - name: centos8 - pre_build_image: true - image: quay.io/paulfantom/molecule-systemd:centos-8 - docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}" - privileged: true - volumes: - - /sys/fs/cgroup:/sys/fs/cgroup:ro - groups: - - python3 - - name: fedora - pre_build_image: true - image: quay.io/paulfantom/molecule-systemd:fedora-30 - docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}" - privileged: true - volumes: - - /sys/fs/cgroup:/sys/fs/cgroup:ro - groups: - - python3 -provisioner: - name: ansible - playbooks: - prepare: prepare.yml - converge: playbook.yml - inventory: - group_vars: - python3: - ansible_python_interpreter: /usr/bin/python3 -verifier: - name: testinfra diff --git a/roles/node_exporter/molecule/alternative/prepare.yml b/roles/node_exporter/molecule/alternative/prepare.yml index 2b2721d7..b56b97c1 100644 --- a/roles/node_exporter/molecule/alternative/prepare.yml +++ b/roles/node_exporter/molecule/alternative/prepare.yml @@ -9,7 +9,7 @@ - name: Download node_exporter binary to local folder become: false ansible.builtin.get_url: - url: "https://github.com/prometheus/node_exporter/releases/download/v{{ node_exporter_version }}/ + url: "https://github.com/prometheus/node_exporter/releases/download/v{{ node_exporter_version }}/\ node_exporter-{{ node_exporter_version }}.linux-{{ go_arch }}.tar.gz" dest: "/tmp/node_exporter-{{ node_exporter_version }}.linux-{{ go_arch }}.tar.gz" mode: 0644 diff --git a/roles/node_exporter/molecule/alternative/tests/test_alternative.py b/roles/node_exporter/molecule/alternative/tests/test_alternative.py index 77d84776..297bf5b9 100644 --- a/roles/node_exporter/molecule/alternative/tests/test_alternative.py +++ b/roles/node_exporter/molecule/alternative/tests/test_alternative.py @@ -1,3 +1,6 @@ +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + import os import testinfra.utils.ansible_runner diff --git a/roles/node_exporter/molecule/default/playbook.yml b/roles/node_exporter/molecule/default/converge.yml similarity index 75% rename from roles/node_exporter/molecule/default/playbook.yml rename to roles/node_exporter/molecule/default/converge.yml index 48cb7859..9ee652ac 100644 --- a/roles/node_exporter/molecule/default/playbook.yml +++ b/roles/node_exporter/molecule/default/converge.yml @@ -3,6 +3,6 @@ hosts: all any_errors_fatal: true roles: - - node_exporter + - prometheus.prometheus.node_exporter vars: node_exporter_web_listen_address: "127.0.0.1:9100" diff --git a/roles/node_exporter/molecule/default/molecule.yml b/roles/node_exporter/molecule/default/molecule.yml index c03bcf2a..ed97d539 100644 --- a/roles/node_exporter/molecule/default/molecule.yml +++ b/roles/node_exporter/molecule/default/molecule.yml @@ -1,70 +1 @@ --- -dependency: - name: galaxy -driver: - name: docker -platforms: - - name: bionic - pre_build_image: true - image: quay.io/paulfantom/molecule-systemd:ubuntu-18.04 - docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}" - privileged: true - volumes: - - /sys/fs/cgroup:/sys/fs/cgroup:ro - - name: xenial - pre_build_image: true - image: quay.io/paulfantom/molecule-systemd:ubuntu-16.04 - docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}" - privileged: true - volumes: - - /sys/fs/cgroup:/sys/fs/cgroup:ro - - name: stretch - pre_build_image: true - image: quay.io/paulfantom/molecule-systemd:debian-9 - docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}" - privileged: true - volumes: - - /sys/fs/cgroup:/sys/fs/cgroup:ro - - name: buster - pre_build_image: true - image: quay.io/paulfantom/molecule-systemd:debian-10 - docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}" - privileged: true - volumes: - - /sys/fs/cgroup:/sys/fs/cgroup:ro - - name: centos7 - pre_build_image: true - image: quay.io/paulfantom/molecule-systemd:centos-7 - docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}" - privileged: true - volumes: - - /sys/fs/cgroup:/sys/fs/cgroup:ro - - name: centos8 - pre_build_image: true - image: quay.io/paulfantom/molecule-systemd:centos-8 - docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}" - privileged: true - volumes: - - /sys/fs/cgroup:/sys/fs/cgroup:ro - groups: - - python3 - - name: fedora - pre_build_image: true - image: quay.io/paulfantom/molecule-systemd:fedora-30 - docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}" - privileged: true - volumes: - - /sys/fs/cgroup:/sys/fs/cgroup:ro - groups: - - python3 -provisioner: - name: ansible - playbooks: - prepare: prepare.yml - converge: playbook.yml - inventory: - group_vars: - python3: - ansible_python_interpreter: /usr/bin/python3 -verifier: - name: testinfra diff --git a/roles/node_exporter/molecule/default/prepare.yml b/roles/node_exporter/molecule/default/prepare.yml deleted file mode 100644 index 5358b3bd..00000000 --- a/roles/node_exporter/molecule/default/prepare.yml +++ /dev/null @@ -1,5 +0,0 @@ ---- -- name: Prepare - hosts: all - gather_facts: false - tasks: [] diff --git a/roles/node_exporter/molecule/default/tests/test_default.py b/roles/node_exporter/molecule/default/tests/test_default.py index 77975888..cb9bf2e3 100644 --- a/roles/node_exporter/molecule/default/tests/test_default.py +++ b/roles/node_exporter/molecule/default/tests/test_default.py @@ -1,3 +1,6 @@ +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + import os import testinfra.utils.ansible_runner diff --git a/roles/node_exporter/molecule/latest/playbook.yml b/roles/node_exporter/molecule/latest/converge.yml similarity index 72% rename from roles/node_exporter/molecule/latest/playbook.yml rename to roles/node_exporter/molecule/latest/converge.yml index 1fb5a6d2..02043853 100644 --- a/roles/node_exporter/molecule/latest/playbook.yml +++ b/roles/node_exporter/molecule/latest/converge.yml @@ -3,6 +3,6 @@ hosts: all any_errors_fatal: true roles: - - node_exporter + - prometheus.prometheus.node_exporter vars: node_exporter_version: latest diff --git a/roles/node_exporter/molecule/latest/molecule.yml b/roles/node_exporter/molecule/latest/molecule.yml index a5a9cebb..ed97d539 100644 --- a/roles/node_exporter/molecule/latest/molecule.yml +++ b/roles/node_exporter/molecule/latest/molecule.yml @@ -1,35 +1 @@ --- -dependency: - name: galaxy -driver: - name: docker -platforms: - - name: buster - pre_build_image: true - image: quay.io/paulfantom/molecule-systemd:debian-10 - docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}" - privileged: true - volumes: - - /sys/fs/cgroup:/sys/fs/cgroup:ro - - name: fedora - pre_build_image: true - image: quay.io/paulfantom/molecule-systemd:fedora-30 - docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}" - privileged: true - volumes: - - /sys/fs/cgroup:/sys/fs/cgroup:ro - groups: - - python3 -provisioner: - name: ansible - playbooks: - create: ../default/create.yml - prepare: ../default/prepare.yml - converge: playbook.yml - destroy: ../default/destroy.yml - inventory: - group_vars: - python3: - ansible_python_interpreter: /usr/bin/python3 -verifier: - name: testinfra diff --git a/roles/node_exporter/molecule/latest/tests/test_alternative.py b/roles/node_exporter/molecule/latest/tests/test_alternative.py index 41ce39ba..11e26ddf 100644 --- a/roles/node_exporter/molecule/latest/tests/test_alternative.py +++ b/roles/node_exporter/molecule/latest/tests/test_alternative.py @@ -1,6 +1,9 @@ -import pytest +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + import os import testinfra.utils.ansible_runner +import pytest testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') diff --git a/roles/node_exporter/tasks/install.yml b/roles/node_exporter/tasks/install.yml index fb771b1c..3e345527 100644 --- a/roles/node_exporter/tasks/install.yml +++ b/roles/node_exporter/tasks/install.yml @@ -24,10 +24,10 @@ - name: Download node_exporter binary to local folder become: false ansible.builtin.get_url: - url: "https://github.com/prometheus/node_exporter/releases/download/v{{ node_exporter_version }}/ + url: "https://github.com/prometheus/node_exporter/releases/download/v{{ node_exporter_version }}/\ node_exporter-{{ node_exporter_version }}.linux-{{ go_arch }}.tar.gz" dest: "/tmp/node_exporter-{{ node_exporter_version }}.linux-{{ go_arch }}.tar.gz" - checksum: "sha256:{{ node_exporter_checksum }}" + checksum: "sha256:{{ __node_exporter_checksum }}" mode: '0644' register: _download_binary until: _download_binary is succeeded diff --git a/roles/node_exporter/tasks/preflight.yml b/roles/node_exporter/tasks/preflight.yml index f843c6b4..34ef6296 100644 --- a/roles/node_exporter/tasks/preflight.yml +++ b/roles/node_exporter/tasks/preflight.yml @@ -71,42 +71,30 @@ - skip_ansible_lint - name: Discover latest version + ansible.builtin.set_fact: + node_exporter_version: "{{ (lookup('url', 'https://api.github.com/repos/prometheus/node_exporter/releases/latest', split_lines=False) | + from_json).get('tag_name') | replace('v', '') }}" + run_once: true + until: node_exporter_version is version('0.0.0', '>=') + retries: 10 when: - node_exporter_version == "latest" - node_exporter_binary_local_dir | length == 0 - delegate_to: localhost - run_once: true - block: - - name: Get latest release - ansible.builtin.uri: - url: "https://api.github.com/repos/prometheus/node_exporter/releases/latest" - method: GET - return_content: true - status_code: 200 - body_format: json - user: "{{ lookup('env', 'GH_USER') | default(omit) }}" - password: "{{ lookup('env', 'GH_TOKEN') | default(omit) }}" - no_log: "{{ not lookup('env', 'MOLECULE_DEBUG') | bool }}" - register: _latest_release - until: _latest_release.status == 200 - retries: 5 - - - name: "Set node_exporter version to {{ _latest_release.json.tag_name[1:] }}" - ansible.builtin.set_fact: - node_exporter_version: "{{ _latest_release.json.tag_name[1:] }}" - name: Get node_exporter binary checksum - delegate_to: localhost when: node_exporter_binary_local_dir | length == 0 block: - name: Get checksum list from github ansible.builtin.set_fact: - _checksums: "{{ lookup('url', 'https://github.com/prometheus/node_exporter/releases/download/v' + node_exporter_version + '/sha256sums.txt', wantlist=True) | list }}" + __node_exporter_checksums: "{{ lookup('url', 'https://github.com/prometheus/node_exporter/releases/download/v' + node_exporter_version + + '/sha256sums.txt', wantlist=True) | list }}" run_once: true + until: __node_exporter_checksums is search('linux-' + go_arch + '.tar.gz') + retries: 10 - name: "Get checksum for {{ go_arch }}" ansible.builtin.set_fact: - node_exporter_checksum: "{{ item.split(' ')[0] }}" - with_items: "{{ _checksums }}" + __node_exporter_checksum: "{{ item.split(' ')[0] }}" + with_items: "{{ __node_exporter_checksums }}" when: - "('linux-' + go_arch + '.tar.gz') in item" diff --git a/roles/node_exporter/test-requirements.txt b/roles/node_exporter/test-requirements.txt new file mode 100644 index 00000000..7f0b6e75 --- /dev/null +++ b/roles/node_exporter/test-requirements.txt @@ -0,0 +1 @@ +bcrypt diff --git a/roles/prometheus/defaults/main.yml b/roles/prometheus/defaults/main.yml index a4a2376e..d9677196 100644 --- a/roles/prometheus/defaults/main.yml +++ b/roles/prometheus/defaults/main.yml @@ -90,6 +90,7 @@ prometheus_static_targets_files: - prometheus/targets/*.yml - prometheus/targets/*.json +# yamllint disable rule:line-length prometheus_alert_rules: # noqa yaml[line-length] # noqa line-length - alert: Watchdog expr: vector(1) @@ -217,3 +218,4 @@ prometheus_alert_rules: # noqa yaml[line-length] # noqa line-length for: 10m labels: severity: warning +# yamllint enable rule:line-length diff --git a/roles/prometheus/molecule/alternative/playbook.yml b/roles/prometheus/molecule/alternative/converge.yml similarity index 98% rename from roles/prometheus/molecule/alternative/playbook.yml rename to roles/prometheus/molecule/alternative/converge.yml index f6847c5c..98104385 100644 --- a/roles/prometheus/molecule/alternative/playbook.yml +++ b/roles/prometheus/molecule/alternative/converge.yml @@ -3,7 +3,7 @@ hosts: all any_errors_fatal: true roles: - - prometheus + - prometheus.prometheus.prometheus vars: prometheus_binary_local_dir: '/tmp/prometheus-linux-amd64' prometheus_config_dir: /opt/prom/etc diff --git a/roles/prometheus/molecule/alternative/molecule.yml b/roles/prometheus/molecule/alternative/molecule.yml index c03bcf2a..ed97d539 100644 --- a/roles/prometheus/molecule/alternative/molecule.yml +++ b/roles/prometheus/molecule/alternative/molecule.yml @@ -1,70 +1 @@ --- -dependency: - name: galaxy -driver: - name: docker -platforms: - - name: bionic - pre_build_image: true - image: quay.io/paulfantom/molecule-systemd:ubuntu-18.04 - docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}" - privileged: true - volumes: - - /sys/fs/cgroup:/sys/fs/cgroup:ro - - name: xenial - pre_build_image: true - image: quay.io/paulfantom/molecule-systemd:ubuntu-16.04 - docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}" - privileged: true - volumes: - - /sys/fs/cgroup:/sys/fs/cgroup:ro - - name: stretch - pre_build_image: true - image: quay.io/paulfantom/molecule-systemd:debian-9 - docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}" - privileged: true - volumes: - - /sys/fs/cgroup:/sys/fs/cgroup:ro - - name: buster - pre_build_image: true - image: quay.io/paulfantom/molecule-systemd:debian-10 - docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}" - privileged: true - volumes: - - /sys/fs/cgroup:/sys/fs/cgroup:ro - - name: centos7 - pre_build_image: true - image: quay.io/paulfantom/molecule-systemd:centos-7 - docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}" - privileged: true - volumes: - - /sys/fs/cgroup:/sys/fs/cgroup:ro - - name: centos8 - pre_build_image: true - image: quay.io/paulfantom/molecule-systemd:centos-8 - docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}" - privileged: true - volumes: - - /sys/fs/cgroup:/sys/fs/cgroup:ro - groups: - - python3 - - name: fedora - pre_build_image: true - image: quay.io/paulfantom/molecule-systemd:fedora-30 - docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}" - privileged: true - volumes: - - /sys/fs/cgroup:/sys/fs/cgroup:ro - groups: - - python3 -provisioner: - name: ansible - playbooks: - prepare: prepare.yml - converge: playbook.yml - inventory: - group_vars: - python3: - ansible_python_interpreter: /usr/bin/python3 -verifier: - name: testinfra diff --git a/roles/prometheus/molecule/alternative/tests/test_alternative.py b/roles/prometheus/molecule/alternative/tests/test_alternative.py index c1e74b8b..0a0cd66d 100644 --- a/roles/prometheus/molecule/alternative/tests/test_alternative.py +++ b/roles/prometheus/molecule/alternative/tests/test_alternative.py @@ -1,6 +1,9 @@ -import pytest +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + import os import testinfra.utils.ansible_runner +import pytest testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') diff --git a/roles/prometheus/molecule/default/playbook.yml b/roles/prometheus/molecule/default/converge.yml similarity index 63% rename from roles/prometheus/molecule/default/playbook.yml rename to roles/prometheus/molecule/default/converge.yml index c03e105c..1bd6466d 100644 --- a/roles/prometheus/molecule/default/playbook.yml +++ b/roles/prometheus/molecule/default/converge.yml @@ -3,4 +3,4 @@ hosts: all any_errors_fatal: true roles: - - prometheus + - prometheus.prometheus.prometheus diff --git a/roles/prometheus/molecule/default/molecule.yml b/roles/prometheus/molecule/default/molecule.yml index 8937ee83..ed97d539 100644 --- a/roles/prometheus/molecule/default/molecule.yml +++ b/roles/prometheus/molecule/default/molecule.yml @@ -1,75 +1 @@ --- -dependency: - name: galaxy -driver: - name: docker -# lint: | -# set -e -# yamllint . -# ansible-lint -# flake8 -platforms: - - name: bionic - pre_build_image: true - image: quay.io/paulfantom/molecule-systemd:ubuntu-18.04 - docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}" - privileged: true - volumes: - - /sys/fs/cgroup:/sys/fs/cgroup:ro - - name: xenial - pre_build_image: true - image: quay.io/paulfantom/molecule-systemd:ubuntu-16.04 - docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}" - privileged: true - volumes: - - /sys/fs/cgroup:/sys/fs/cgroup:ro - - name: stretch - pre_build_image: true - image: quay.io/paulfantom/molecule-systemd:debian-9 - docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}" - privileged: true - volumes: - - /sys/fs/cgroup:/sys/fs/cgroup:ro - - name: buster - pre_build_image: true - image: quay.io/paulfantom/molecule-systemd:debian-10 - docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}" - privileged: true - volumes: - - /sys/fs/cgroup:/sys/fs/cgroup:ro - - name: centos7 - pre_build_image: true - image: quay.io/paulfantom/molecule-systemd:centos-7 - docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}" - privileged: true - volumes: - - /sys/fs/cgroup:/sys/fs/cgroup:ro - - name: centos8 - pre_build_image: true - image: quay.io/paulfantom/molecule-systemd:centos-8 - docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}" - privileged: true - volumes: - - /sys/fs/cgroup:/sys/fs/cgroup:ro - groups: - - python3 - - name: fedora - pre_build_image: true - image: quay.io/paulfantom/molecule-systemd:fedora-30 - docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}" - privileged: true - volumes: - - /sys/fs/cgroup:/sys/fs/cgroup:ro - groups: - - python3 -provisioner: - name: ansible - playbooks: - prepare: prepare.yml - converge: playbook.yml - inventory: - group_vars: - python3: - ansible_python_interpreter: /usr/bin/python3 -verifier: - name: testinfra diff --git a/roles/prometheus/molecule/default/prepare.yml b/roles/prometheus/molecule/default/prepare.yml deleted file mode 100644 index 5358b3bd..00000000 --- a/roles/prometheus/molecule/default/prepare.yml +++ /dev/null @@ -1,5 +0,0 @@ ---- -- name: Prepare - hosts: all - gather_facts: false - tasks: [] diff --git a/roles/prometheus/molecule/default/tests/test_default.py b/roles/prometheus/molecule/default/tests/test_default.py index 23cb4d54..b9008eae 100644 --- a/roles/prometheus/molecule/default/tests/test_default.py +++ b/roles/prometheus/molecule/default/tests/test_default.py @@ -1,7 +1,10 @@ -import pytest +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + import os import yaml import testinfra.utils.ansible_runner +import pytest testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') @@ -10,7 +13,7 @@ testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( @pytest.fixture() def AnsibleDefaults(): with open("defaults/main.yml", 'r') as stream: - return yaml.load(stream) + return yaml.full_load(stream) @pytest.mark.parametrize("dirs", [ @@ -69,5 +72,5 @@ def test_socket(host): def test_version(host, AnsibleDefaults): version = os.getenv('PROMETHEUS', AnsibleDefaults['prometheus_version']) run = host.run("/usr/local/bin/prometheus --version") - out = run.stdout+run.stderr + out = run.stdout + run.stderr assert "prometheus, version " + version in out diff --git a/roles/prometheus/molecule/latest/playbook.yml b/roles/prometheus/molecule/latest/converge.yml similarity index 73% rename from roles/prometheus/molecule/latest/playbook.yml rename to roles/prometheus/molecule/latest/converge.yml index 14b722d4..2797ceba 100644 --- a/roles/prometheus/molecule/latest/playbook.yml +++ b/roles/prometheus/molecule/latest/converge.yml @@ -3,6 +3,6 @@ hosts: all any_errors_fatal: true roles: - - prometheus + - prometheus.prometheus.prometheus vars: prometheus_version: latest diff --git a/roles/prometheus/molecule/latest/molecule.yml b/roles/prometheus/molecule/latest/molecule.yml index a5a9cebb..ed97d539 100644 --- a/roles/prometheus/molecule/latest/molecule.yml +++ b/roles/prometheus/molecule/latest/molecule.yml @@ -1,35 +1 @@ --- -dependency: - name: galaxy -driver: - name: docker -platforms: - - name: buster - pre_build_image: true - image: quay.io/paulfantom/molecule-systemd:debian-10 - docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}" - privileged: true - volumes: - - /sys/fs/cgroup:/sys/fs/cgroup:ro - - name: fedora - pre_build_image: true - image: quay.io/paulfantom/molecule-systemd:fedora-30 - docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}" - privileged: true - volumes: - - /sys/fs/cgroup:/sys/fs/cgroup:ro - groups: - - python3 -provisioner: - name: ansible - playbooks: - create: ../default/create.yml - prepare: ../default/prepare.yml - converge: playbook.yml - destroy: ../default/destroy.yml - inventory: - group_vars: - python3: - ansible_python_interpreter: /usr/bin/python3 -verifier: - name: testinfra diff --git a/roles/prometheus/molecule/latest/tests/test_alternative.py b/roles/prometheus/molecule/latest/tests/test_alternative.py index cbefab91..619f92dd 100644 --- a/roles/prometheus/molecule/latest/tests/test_alternative.py +++ b/roles/prometheus/molecule/latest/tests/test_alternative.py @@ -1,6 +1,9 @@ -import pytest +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + import os import testinfra.utils.ansible_runner +import pytest testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') diff --git a/roles/prometheus/tasks/configure.yml b/roles/prometheus/tasks/configure.yml index 8a3522fa..bcdbbffd 100644 --- a/roles/prometheus/tasks/configure.yml +++ b/roles/prometheus/tasks/configure.yml @@ -37,7 +37,7 @@ - reload prometheus - name: Configure Prometheus web - ansible.builtin.template: + ansible.builtin.copy: content: "{{ prometheus_web_config | to_nice_yaml(indent=2, sort_keys=False) }}" dest: "{{ prometheus_config_dir }}/web.yml" force: true @@ -46,10 +46,9 @@ mode: 0640 - name: Configure prometheus static targets - ansible.builtin.template: + ansible.builtin.copy: content: | {{ item.value | to_nice_yaml(indent=2, sort_keys=False) }} - lstrip_blocks: true dest: "{{ prometheus_config_dir }}/file_sd/{{ item.key }}.yml" force: true owner: root diff --git a/roles/prometheus/tasks/install.yml b/roles/prometheus/tasks/install.yml index 26fe2765..0055cfcb 100644 --- a/roles/prometheus/tasks/install.yml +++ b/roles/prometheus/tasks/install.yml @@ -43,7 +43,7 @@ - name: Download prometheus binary to local folder become: false ansible.builtin.get_url: - url: "https://github.com/prometheus/prometheus/releases/download/v{{ prometheus_version }}/ + url: "https://github.com/prometheus/prometheus/releases/download/v{{ prometheus_version }}/\ prometheus-{{ prometheus_version }}.linux-{{ go_arch }}.tar.gz" dest: "/tmp/prometheus-{{ prometheus_version }}.linux-{{ go_arch }}.tar.gz" checksum: "sha256:{{ __prometheus_checksum }}" diff --git a/roles/prometheus/tasks/preflight.yml b/roles/prometheus/tasks/preflight.yml index a63b062e..7db7b1a3 100644 --- a/roles/prometheus/tasks/preflight.yml +++ b/roles/prometheus/tasks/preflight.yml @@ -73,41 +73,29 @@ - prometheus_alert_rules != [] - name: Discover latest version + ansible.builtin.set_fact: + prometheus_version: "{{ (lookup('url', 'https://api.github.com/repos/prometheus/prometheus/releases/latest', split_lines=False) | + from_json).get('tag_name') | replace('v', '') }}" + run_once: true + until: prometheus_version is version('0.0.0', '>=') + retries: 10 when: - prometheus_version == "latest" - prometheus_binary_local_dir | length == 0 - not prometheus_skip_install - block: - - - name: Get latest release - ansible.builtin.uri: - url: "https://api.github.com/repos/prometheus/prometheus/releases/latest" - method: GET - return_content: true - status_code: 200 - body_format: json - validate_certs: false - user: "{{ lookup('env', 'GH_USER') | default(omit) }}" - password: "{{ lookup('env', 'GH_TOKEN') | default(omit) }}" - no_log: "{{ not lookup('env', 'ANSIBLE_DEBUG') | bool }}" - register: _latest_release - until: _latest_release.status == 200 - retries: 5 - - - name: "Set prometheus version to {{ _latest_release.json.tag_name[1:] }}" - ansible.builtin.set_fact: - prometheus_version: "{{ _latest_release.json.tag_name[1:] }}" - name: Get prometheus binary checksum - delegate_to: localhost when: - prometheus_binary_local_dir | length == 0 - not prometheus_skip_install block: - name: "Get checksum list" ansible.builtin.set_fact: - __prometheus_checksums: "{{ lookup('url', 'https://github.com/prometheus/prometheus/releases/download/v' + prometheus_version + '/sha256sums.txt', wantlist=True) | list }}" + __prometheus_checksums: "{{ lookup('url', 'https://github.com/prometheus/prometheus/releases/download/v' + prometheus_version + '/sha256sums.txt', + wantlist=True) | list }}" run_once: true + until: __prometheus_checksums is search('linux-' + go_arch + '.tar.gz') + retries: 10 - name: "Get checksum for {{ go_arch }}" ansible.builtin.set_fact: diff --git a/roles/snmp_exporter/molecule/alternative/playbook.yml b/roles/snmp_exporter/molecule/alternative/converge.yml similarity index 80% rename from roles/snmp_exporter/molecule/alternative/playbook.yml rename to roles/snmp_exporter/molecule/alternative/converge.yml index 920a3c41..fd33b197 100644 --- a/roles/snmp_exporter/molecule/alternative/playbook.yml +++ b/roles/snmp_exporter/molecule/alternative/converge.yml @@ -2,7 +2,7 @@ - name: Converge hosts: all roles: - - snmp_exporter + - prometheus.prometheus.snmp_exporter vars: __testing_on_travis: true snmp_exporter_web_listen_address: "127.0.0.1:9116" diff --git a/roles/snmp_exporter/molecule/alternative/molecule.yml b/roles/snmp_exporter/molecule/alternative/molecule.yml index c03bcf2a..ed97d539 100644 --- a/roles/snmp_exporter/molecule/alternative/molecule.yml +++ b/roles/snmp_exporter/molecule/alternative/molecule.yml @@ -1,70 +1 @@ --- -dependency: - name: galaxy -driver: - name: docker -platforms: - - name: bionic - pre_build_image: true - image: quay.io/paulfantom/molecule-systemd:ubuntu-18.04 - docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}" - privileged: true - volumes: - - /sys/fs/cgroup:/sys/fs/cgroup:ro - - name: xenial - pre_build_image: true - image: quay.io/paulfantom/molecule-systemd:ubuntu-16.04 - docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}" - privileged: true - volumes: - - /sys/fs/cgroup:/sys/fs/cgroup:ro - - name: stretch - pre_build_image: true - image: quay.io/paulfantom/molecule-systemd:debian-9 - docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}" - privileged: true - volumes: - - /sys/fs/cgroup:/sys/fs/cgroup:ro - - name: buster - pre_build_image: true - image: quay.io/paulfantom/molecule-systemd:debian-10 - docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}" - privileged: true - volumes: - - /sys/fs/cgroup:/sys/fs/cgroup:ro - - name: centos7 - pre_build_image: true - image: quay.io/paulfantom/molecule-systemd:centos-7 - docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}" - privileged: true - volumes: - - /sys/fs/cgroup:/sys/fs/cgroup:ro - - name: centos8 - pre_build_image: true - image: quay.io/paulfantom/molecule-systemd:centos-8 - docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}" - privileged: true - volumes: - - /sys/fs/cgroup:/sys/fs/cgroup:ro - groups: - - python3 - - name: fedora - pre_build_image: true - image: quay.io/paulfantom/molecule-systemd:fedora-30 - docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}" - privileged: true - volumes: - - /sys/fs/cgroup:/sys/fs/cgroup:ro - groups: - - python3 -provisioner: - name: ansible - playbooks: - prepare: prepare.yml - converge: playbook.yml - inventory: - group_vars: - python3: - ansible_python_interpreter: /usr/bin/python3 -verifier: - name: testinfra diff --git a/roles/snmp_exporter/molecule/alternative/prepare.yml b/roles/snmp_exporter/molecule/alternative/prepare.yml deleted file mode 100644 index 5358b3bd..00000000 --- a/roles/snmp_exporter/molecule/alternative/prepare.yml +++ /dev/null @@ -1,5 +0,0 @@ ---- -- name: Prepare - hosts: all - gather_facts: false - tasks: [] diff --git a/roles/snmp_exporter/molecule/alternative/tests/test_alternative.py b/roles/snmp_exporter/molecule/alternative/tests/test_alternative.py index 5341d88a..6670272d 100644 --- a/roles/snmp_exporter/molecule/alternative/tests/test_alternative.py +++ b/roles/snmp_exporter/molecule/alternative/tests/test_alternative.py @@ -1,6 +1,9 @@ -import pytest +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + import os import testinfra.utils.ansible_runner +import pytest testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') diff --git a/roles/snmp_exporter/molecule/default/playbook.yml b/roles/snmp_exporter/molecule/default/converge.yml similarity index 76% rename from roles/snmp_exporter/molecule/default/playbook.yml rename to roles/snmp_exporter/molecule/default/converge.yml index 238b0910..1bc7740f 100644 --- a/roles/snmp_exporter/molecule/default/playbook.yml +++ b/roles/snmp_exporter/molecule/default/converge.yml @@ -2,7 +2,7 @@ - name: Converge hosts: all roles: - - snmp_exporter + - prometheus.prometheus.snmp_exporter vars: __testing_on_travis: true snmp_exporter_web_listen_address: "127.0.0.1:9116" diff --git a/roles/snmp_exporter/molecule/default/molecule.yml b/roles/snmp_exporter/molecule/default/molecule.yml index c03bcf2a..ed97d539 100644 --- a/roles/snmp_exporter/molecule/default/molecule.yml +++ b/roles/snmp_exporter/molecule/default/molecule.yml @@ -1,70 +1 @@ --- -dependency: - name: galaxy -driver: - name: docker -platforms: - - name: bionic - pre_build_image: true - image: quay.io/paulfantom/molecule-systemd:ubuntu-18.04 - docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}" - privileged: true - volumes: - - /sys/fs/cgroup:/sys/fs/cgroup:ro - - name: xenial - pre_build_image: true - image: quay.io/paulfantom/molecule-systemd:ubuntu-16.04 - docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}" - privileged: true - volumes: - - /sys/fs/cgroup:/sys/fs/cgroup:ro - - name: stretch - pre_build_image: true - image: quay.io/paulfantom/molecule-systemd:debian-9 - docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}" - privileged: true - volumes: - - /sys/fs/cgroup:/sys/fs/cgroup:ro - - name: buster - pre_build_image: true - image: quay.io/paulfantom/molecule-systemd:debian-10 - docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}" - privileged: true - volumes: - - /sys/fs/cgroup:/sys/fs/cgroup:ro - - name: centos7 - pre_build_image: true - image: quay.io/paulfantom/molecule-systemd:centos-7 - docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}" - privileged: true - volumes: - - /sys/fs/cgroup:/sys/fs/cgroup:ro - - name: centos8 - pre_build_image: true - image: quay.io/paulfantom/molecule-systemd:centos-8 - docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}" - privileged: true - volumes: - - /sys/fs/cgroup:/sys/fs/cgroup:ro - groups: - - python3 - - name: fedora - pre_build_image: true - image: quay.io/paulfantom/molecule-systemd:fedora-30 - docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}" - privileged: true - volumes: - - /sys/fs/cgroup:/sys/fs/cgroup:ro - groups: - - python3 -provisioner: - name: ansible - playbooks: - prepare: prepare.yml - converge: playbook.yml - inventory: - group_vars: - python3: - ansible_python_interpreter: /usr/bin/python3 -verifier: - name: testinfra diff --git a/roles/snmp_exporter/molecule/default/prepare.yml b/roles/snmp_exporter/molecule/default/prepare.yml deleted file mode 100644 index 5358b3bd..00000000 --- a/roles/snmp_exporter/molecule/default/prepare.yml +++ /dev/null @@ -1,5 +0,0 @@ ---- -- name: Prepare - hosts: all - gather_facts: false - tasks: [] diff --git a/roles/snmp_exporter/molecule/default/tests/test_default.py b/roles/snmp_exporter/molecule/default/tests/test_default.py index 5341d88a..6670272d 100644 --- a/roles/snmp_exporter/molecule/default/tests/test_default.py +++ b/roles/snmp_exporter/molecule/default/tests/test_default.py @@ -1,6 +1,9 @@ -import pytest +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + import os import testinfra.utils.ansible_runner +import pytest testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') diff --git a/roles/snmp_exporter/tasks/configure.yml b/roles/snmp_exporter/tasks/configure.yml index 82978b61..18039bb9 100644 --- a/roles/snmp_exporter/tasks/configure.yml +++ b/roles/snmp_exporter/tasks/configure.yml @@ -23,7 +23,7 @@ delay: 2 notify: - reload snmp exporter - when: snmp_exporter_config_file == "" + when: not (snmp_exporter_config_file) - name: Copy configuration file ansible.builtin.template: @@ -35,4 +35,4 @@ no_log: "{{ 'true' if __testing_on_travis is defined else 'false' }}" notify: - reload snmp exporter - when: snmp_exporter_config_file != "" + when: (snmp_exporter_config_file) diff --git a/roles/snmp_exporter/tasks/install.yml b/roles/snmp_exporter/tasks/install.yml index 38c2dbdf..b2a16fb6 100644 --- a/roles/snmp_exporter/tasks/install.yml +++ b/roles/snmp_exporter/tasks/install.yml @@ -2,7 +2,7 @@ - name: Download snmp_exporter binary to local folder become: false ansible.builtin.get_url: - url: "https://github.com/prometheus/snmp_exporter/releases/download/v{{ snmp_exporter_version }}/ + url: "https://github.com/prometheus/snmp_exporter/releases/download/v{{ snmp_exporter_version }}/\ snmp_exporter-{{ snmp_exporter_version }}.linux-{{ go_arch_map[ansible_architecture] | default(ansible_architecture) }}.tar.gz" dest: "/tmp" checksum: "sha256:{{ snmp_exporter_checksum }}" diff --git a/roles/snmp_exporter/test-requirements.txt b/roles/snmp_exporter/test-requirements.txt deleted file mode 100644 index 1b6e9a96..00000000 --- a/roles/snmp_exporter/test-requirements.txt +++ /dev/null @@ -1,8 +0,0 @@ -molecule>=3.0.0 -molecule-docker -docker -ansible-lint>=3.4.0 -testinfra>=1.7.0 -jmespath -selinux -passlib diff --git a/test-requirements.txt b/test-requirements.txt index 780a5a7a..88cefd1d 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -1,10 +1,8 @@ -# temporarily lock versions of molecule and ansible-compat to avoid a bug: -ansible-compat==0.5.0 -molecule==3.5.2 -molecule-docker +molecule docker -ansible-lint>=3.4.0 -testinfra>=1.7.0 +ansible-lint +pytest-testinfra jmespath selinux passlib +yamllint diff --git a/tests/integration/molecule.sh b/tests/integration/molecule.sh new file mode 100755 index 00000000..6f8294af --- /dev/null +++ b/tests/integration/molecule.sh @@ -0,0 +1,42 @@ +#!/usr/bin/env bash + +collection_root=$(pwd | grep -oP ".+\/ansible_collections\/\w+?\/\w+") +targetname=${PWD##*/} +role=$(expr "$targetname" : '\w*-\(\w*\)-\w*') +role_root="$collection_root/roles/$role" +scenario=$(expr "$targetname" : '\w*-\w*-\(\w*\)') +ansible_version="$(ansible --version | head -1 | sed 's/[^0-9\.]*//g')" + +# Install package requirements +apt -y update +apt -y install docker.io + +# Install test requirements from role +if [ -f "$role_root/test-requirements.txt" ]; then + python -m pip install -r "$role_root/test-requirements.txt" +fi +# Install test requirements from collection +if [ -f "$collection_root/test-requirements.txt" ]; then + python -m pip install -r "$collection_root/test-requirements.txt" +fi + +# Install ansible version specific requirements +if [ "$(printf '%s\n' "2.12" "$ansible_version" | sort -V | head -n1)" = "2.12" ]; then + python -m pip install molecule molecule-plugins[docker] +else + python -m pip install molecule molecule-docker + ansible-galaxy collection install community.docker + ansible-galaxy collection install -r "$collection_root/requirements.yml" +fi + +# Define config locations within collection +export MOLECULE_FILE=$collection_root/.config/molecule/config.yml +export YAMLLINT_CONFIG_FILE=$collection_root/.config/yamllint/config.yml + +# Unset ansible-test variables that break molecule +unset _ANSIBLE_COVERAGE_CONFIG +unset ANSIBLE_PYTHON_INTERPRETER + +# Run molecule test +cd "$role_root" +molecule -c "$collection_root/.config/molecule/config.yml" test -s "$scenario" diff --git a/tests/integration/targets/molecule-alertmanager-alternative/runme.sh b/tests/integration/targets/molecule-alertmanager-alternative/runme.sh new file mode 100755 index 00000000..d094c3e1 --- /dev/null +++ b/tests/integration/targets/molecule-alertmanager-alternative/runme.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +collection_root=$(pwd | grep -oP ".+\/ansible_collections\/\w+?\/\w+") +source "$collection_root/tests/integration/molecule.sh" diff --git a/tests/integration/targets/molecule-alertmanager-default/runme.sh b/tests/integration/targets/molecule-alertmanager-default/runme.sh new file mode 100755 index 00000000..d094c3e1 --- /dev/null +++ b/tests/integration/targets/molecule-alertmanager-default/runme.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +collection_root=$(pwd | grep -oP ".+\/ansible_collections\/\w+?\/\w+") +source "$collection_root/tests/integration/molecule.sh" diff --git a/tests/integration/targets/molecule-alertmanager-latest/runme.sh b/tests/integration/targets/molecule-alertmanager-latest/runme.sh new file mode 100755 index 00000000..d094c3e1 --- /dev/null +++ b/tests/integration/targets/molecule-alertmanager-latest/runme.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +collection_root=$(pwd | grep -oP ".+\/ansible_collections\/\w+?\/\w+") +source "$collection_root/tests/integration/molecule.sh" diff --git a/tests/integration/targets/molecule-blackbox_exporter-alternative/runme.sh b/tests/integration/targets/molecule-blackbox_exporter-alternative/runme.sh new file mode 100755 index 00000000..d094c3e1 --- /dev/null +++ b/tests/integration/targets/molecule-blackbox_exporter-alternative/runme.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +collection_root=$(pwd | grep -oP ".+\/ansible_collections\/\w+?\/\w+") +source "$collection_root/tests/integration/molecule.sh" diff --git a/tests/integration/targets/molecule-blackbox_exporter-default/runme.sh b/tests/integration/targets/molecule-blackbox_exporter-default/runme.sh new file mode 100755 index 00000000..d094c3e1 --- /dev/null +++ b/tests/integration/targets/molecule-blackbox_exporter-default/runme.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +collection_root=$(pwd | grep -oP ".+\/ansible_collections\/\w+?\/\w+") +source "$collection_root/tests/integration/molecule.sh" diff --git a/tests/integration/targets/molecule-node_exporter-alternative/runme.sh b/tests/integration/targets/molecule-node_exporter-alternative/runme.sh new file mode 100755 index 00000000..d094c3e1 --- /dev/null +++ b/tests/integration/targets/molecule-node_exporter-alternative/runme.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +collection_root=$(pwd | grep -oP ".+\/ansible_collections\/\w+?\/\w+") +source "$collection_root/tests/integration/molecule.sh" diff --git a/tests/integration/targets/molecule-node_exporter-default/runme.sh b/tests/integration/targets/molecule-node_exporter-default/runme.sh new file mode 100755 index 00000000..d094c3e1 --- /dev/null +++ b/tests/integration/targets/molecule-node_exporter-default/runme.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +collection_root=$(pwd | grep -oP ".+\/ansible_collections\/\w+?\/\w+") +source "$collection_root/tests/integration/molecule.sh" diff --git a/tests/integration/targets/molecule-node_exporter-latest/runme.sh b/tests/integration/targets/molecule-node_exporter-latest/runme.sh new file mode 100755 index 00000000..d094c3e1 --- /dev/null +++ b/tests/integration/targets/molecule-node_exporter-latest/runme.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +collection_root=$(pwd | grep -oP ".+\/ansible_collections\/\w+?\/\w+") +source "$collection_root/tests/integration/molecule.sh" diff --git a/tests/integration/targets/molecule-prometheus-alternative/runme.sh b/tests/integration/targets/molecule-prometheus-alternative/runme.sh new file mode 100755 index 00000000..d094c3e1 --- /dev/null +++ b/tests/integration/targets/molecule-prometheus-alternative/runme.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +collection_root=$(pwd | grep -oP ".+\/ansible_collections\/\w+?\/\w+") +source "$collection_root/tests/integration/molecule.sh" diff --git a/tests/integration/targets/molecule-prometheus-default/runme.sh b/tests/integration/targets/molecule-prometheus-default/runme.sh new file mode 100755 index 00000000..d094c3e1 --- /dev/null +++ b/tests/integration/targets/molecule-prometheus-default/runme.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +collection_root=$(pwd | grep -oP ".+\/ansible_collections\/\w+?\/\w+") +source "$collection_root/tests/integration/molecule.sh" diff --git a/tests/integration/targets/molecule-prometheus-latest/runme.sh b/tests/integration/targets/molecule-prometheus-latest/runme.sh new file mode 100755 index 00000000..d094c3e1 --- /dev/null +++ b/tests/integration/targets/molecule-prometheus-latest/runme.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +collection_root=$(pwd | grep -oP ".+\/ansible_collections\/\w+?\/\w+") +source "$collection_root/tests/integration/molecule.sh" diff --git a/tests/integration/targets/molecule-snmp_exporter-alternative/runme.sh b/tests/integration/targets/molecule-snmp_exporter-alternative/runme.sh new file mode 100755 index 00000000..d094c3e1 --- /dev/null +++ b/tests/integration/targets/molecule-snmp_exporter-alternative/runme.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +collection_root=$(pwd | grep -oP ".+\/ansible_collections\/\w+?\/\w+") +source "$collection_root/tests/integration/molecule.sh" diff --git a/tests/integration/targets/molecule-snmp_exporter-default/runme.sh b/tests/integration/targets/molecule-snmp_exporter-default/runme.sh new file mode 100755 index 00000000..d094c3e1 --- /dev/null +++ b/tests/integration/targets/molecule-snmp_exporter-default/runme.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +collection_root=$(pwd | grep -oP ".+\/ansible_collections\/\w+?\/\w+") +source "$collection_root/tests/integration/molecule.sh"