diff --git a/.github/workflows/ee.yml b/.github/workflows/ee.yml new file mode 100644 index 0000000..61d605e --- /dev/null +++ b/.github/workflows/ee.yml @@ -0,0 +1,108 @@ +--- +name: execution environment +on: + # Run CI against all pushes (direct commits, also merged PRs), Pull Requests + push: + branches: + - main + - stable-* + pull_request: + # Run CI once per day (at 04:45 UTC) + # This ensures that even if there haven't been commits that we are still testing against latest version of ansible-builder + schedule: + - cron: '45 4 * * *' + +env: + NAMESPACE: community + COLLECTION_NAME: hrobot + +jobs: + build: + name: Build and test EE (Ⓐ${{ matrix.runner_tag }}) + strategy: + matrix: + runner_tag: + - devel + - stable-2.12-latest + - stable-2.11-latest + - stable-2.9-latest + runs-on: ubuntu-latest + steps: + - name: Check out code + uses: actions/checkout@v3 + with: + path: ansible_collections/${{ env.NAMESPACE }}/${{ env.COLLECTION_NAME }} + + - name: Set up Python + uses: actions/setup-python@v3 + with: + python-version: '3.10' + + - name: Install ansible-builder and ansible-navigator + run: pip install ansible-builder ansible-navigator + + - name: Verify requirements + run: ansible-builder introspect --sanitize . + + - name: Make sure galaxy.yml has version entry + run: >- + python -c + 'import yaml ; + f = open("galaxy.yml", "rb") ; + data = yaml.safe_load(f) ; + f.close() ; + data["version"] = data.get("version") or "0.0.1" ; + f = open("galaxy.yml", "wb") ; + f.write(yaml.dump(data).encode("utf-8")) ; + f.close() ; + ' + working-directory: ansible_collections/${{ env.NAMESPACE }}/${{ env.COLLECTION_NAME }} + + - name: Build collection + run: | + ansible-galaxy collection build --output-path ../../../ + working-directory: ansible_collections/${{ env.NAMESPACE }}/${{ env.COLLECTION_NAME }} + + - name: Create files for building execution environment + run: | + COLLECTION_FILENAME="$(ls "${{ env.NAMESPACE }}-${{ env.COLLECTION_NAME }}"-*.tar.gz)" + + # EE config + cat > execution-environment.yml < requirements.yml < + ansible-navigator run + --mode stdout + --pull-policy never + --set-environment-variable ANSIBLE_PRIVATE_ROLE_VARS=true + --execution-environment-image test-ee:latest + all.yml + working-directory: ansible_collections/${{ env.NAMESPACE }}/${{ env.COLLECTION_NAME }}/tests/ee diff --git a/changelogs/fragments/45-ee.yml b/changelogs/fragments/45-ee.yml new file mode 100644 index 0000000..b512a05 --- /dev/null +++ b/changelogs/fragments/45-ee.yml @@ -0,0 +1,2 @@ +minor_changes: + - "Prepare collection for inclusion in an Execution Environment by declaring its dependencies (https://github.com/ansible-collections/community.hrobot/pull/45)." diff --git a/meta/execution-environment.yml b/meta/execution-environment.yml new file mode 100644 index 0000000..c6e7fbc --- /dev/null +++ b/meta/execution-environment.yml @@ -0,0 +1,3 @@ +--- +version: 1 +dependencies: {} diff --git a/tests/ee/all.yml b/tests/ee/all.yml new file mode 100644 index 0000000..1a937d4 --- /dev/null +++ b/tests/ee/all.yml @@ -0,0 +1,13 @@ +- hosts: localhost + tasks: + - name: Find all roles + find: + paths: + - "{{ playbook_dir ~ '/roles/' }}" + file_type: directory + depth: 1 + register: result + - name: Include all roles + include_role: + name: "{{ item }}" + loop: "{{ result.files | map(attribute='path') | map('regex_replace', '.*/', '') | sort }}" diff --git a/tests/ee/roles/smoke/library/smoke_ipaddress.py b/tests/ee/roles/smoke/library/smoke_ipaddress.py new file mode 100644 index 0000000..a737353 --- /dev/null +++ b/tests/ee/roles/smoke/library/smoke_ipaddress.py @@ -0,0 +1,48 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +# (c) 2022 Felix Fontein +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + + +DOCUMENTATION = r''' +--- +module: smoke_ipaddress +short_description: Check whether ipaddress is present +author: + - Felix Fontein (@felixfontein) +description: + - Check whether C(ipaddress) is present. +options: {} +''' + +EXAMPLES = r''' # ''' + +RETURN = r''' # ''' + +import traceback + +from ansible.module_utils.basic import AnsibleModule, missing_required_lib + +try: + import ipaddress + HAS_IPADDRESS = True +except ImportError as exc: + IPADDRESS_IMP_ERR = traceback.format_exc() + HAS_IPADDRESS = False + + +def main(): + module = AnsibleModule(argument_spec=dict(), supports_check_mode=True) + + if not HAS_IPADDRESS: + module.fail_json(msg=missing_required_lib('ipaddress'), exception=IPADDRESS_IMP_ERR) + + module.exit_json(msg='Everything is ok') + + +if __name__ == '__main__': # pragma: no cover + main() # pragma: no cover diff --git a/tests/ee/roles/smoke/tasks/main.yml b/tests/ee/roles/smoke/tasks/main.yml new file mode 100644 index 0000000..45bcef3 --- /dev/null +++ b/tests/ee/roles/smoke/tasks/main.yml @@ -0,0 +1,25 @@ +--- +- name: Check whether ipaddress is present + smoke_ipaddress: + register: result + +- name: Validate result + assert: + that: + - result.msg == 'Everything is ok' + +- name: Check ssh_key module with invalid fingerprint + community.hrobot.ssh_key: + hetzner_user: foo + hetzner_password: bar + name: baz + state: absent + fingerprint: f0:0b + ignore_errors: true + register: result + +- name: Validate result + assert: + that: + - result is failed + - "result.msg == 'Fingerprint must consist of 16 8-bit hex numbers: got 2 8-bit hex numbers instead'" diff --git a/tests/sanity/ignore-2.10.txt b/tests/sanity/ignore-2.10.txt index cd8f037..3ab4aa4 100644 --- a/tests/sanity/ignore-2.10.txt +++ b/tests/sanity/ignore-2.10.txt @@ -2,3 +2,4 @@ plugins/modules/boot.py validate-modules:return-syntax-error # only allowed in plugins/modules/firewall.py pylint:bad-option-value # a pylint test that is disabled was modified over time plugins/modules/server.py validate-modules:return-syntax-error # only allowed in 2.13+ plugins/modules/server_info.py validate-modules:return-syntax-error # only allowed in 2.13+ +tests/ee/roles/smoke/library/smoke_ipaddress.py shebang diff --git a/tests/sanity/ignore-2.11.txt b/tests/sanity/ignore-2.11.txt index 35c6782..749dbc5 100644 --- a/tests/sanity/ignore-2.11.txt +++ b/tests/sanity/ignore-2.11.txt @@ -1,3 +1,4 @@ plugins/modules/boot.py validate-modules:return-syntax-error # only allowed in 2.13+ plugins/modules/server.py validate-modules:return-syntax-error # only allowed in 2.13+ plugins/modules/server_info.py validate-modules:return-syntax-error # only allowed in 2.13+ +tests/ee/roles/smoke/library/smoke_ipaddress.py shebang diff --git a/tests/sanity/ignore-2.12.txt b/tests/sanity/ignore-2.12.txt index 35c6782..749dbc5 100644 --- a/tests/sanity/ignore-2.12.txt +++ b/tests/sanity/ignore-2.12.txt @@ -1,3 +1,4 @@ plugins/modules/boot.py validate-modules:return-syntax-error # only allowed in 2.13+ plugins/modules/server.py validate-modules:return-syntax-error # only allowed in 2.13+ plugins/modules/server_info.py validate-modules:return-syntax-error # only allowed in 2.13+ +tests/ee/roles/smoke/library/smoke_ipaddress.py shebang diff --git a/tests/sanity/ignore-2.13.txt b/tests/sanity/ignore-2.13.txt new file mode 100644 index 0000000..0d9329f --- /dev/null +++ b/tests/sanity/ignore-2.13.txt @@ -0,0 +1 @@ +tests/ee/roles/smoke/library/smoke_ipaddress.py shebang diff --git a/tests/sanity/ignore-2.14.txt b/tests/sanity/ignore-2.14.txt new file mode 100644 index 0000000..0d9329f --- /dev/null +++ b/tests/sanity/ignore-2.14.txt @@ -0,0 +1 @@ +tests/ee/roles/smoke/library/smoke_ipaddress.py shebang diff --git a/tests/sanity/ignore-2.9.txt b/tests/sanity/ignore-2.9.txt index b98fbd3..fd7a4e7 100644 --- a/tests/sanity/ignore-2.9.txt +++ b/tests/sanity/ignore-2.9.txt @@ -1,2 +1,3 @@ plugins/modules/boot.py validate-modules:return-syntax-error # only allowed in 2.13+ plugins/modules/firewall.py pylint:bad-option-value # a pylint test that is disabled was modified over time +tests/ee/roles/smoke/library/smoke_ipaddress.py shebang