Skip to content

Commit

Permalink
Make EE ready (#45)
Browse files Browse the repository at this point in the history
* Make EE ready.

* Linting.

* Try other shebang.

* Use module shebang, simply ignore errors.
  • Loading branch information
felixfontein authored Apr 15, 2022
1 parent ddbe883 commit e8adbe9
Show file tree
Hide file tree
Showing 12 changed files with 205 additions and 0 deletions.
108 changes: 108 additions & 0 deletions .github/workflows/ee.yml
Original file line number Diff line number Diff line change
@@ -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 <<EOF
---
version: 1
build_arg_defaults:
EE_BASE_IMAGE: 'quay.io/ansible/ansible-runner:${{ matrix.runner_tag }}'
dependencies:
galaxy: requirements.yml
EOF
echo "::group::execution-environment.yml"
cat execution-environment.yml
echo "::endgroup::"
# Requirements
cat > requirements.yml <<EOF
---
collections:
- name: ${COLLECTION_FILENAME}
type: file
EOF
echo "::group::requirements.yml"
cat requirements.yml
echo "::endgroup::"
- name: Build image based on ${{ matrix.runner_tag }}
run: |
mkdir -p context/_build/
cp "${{ env.NAMESPACE }}-${{ env.COLLECTION_NAME }}"-*.tar.gz context/_build/
ansible-builder build -v 3 -t test-ee:latest --container-runtime=podman
- name: Run basic tests
run: >
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
2 changes: 2 additions & 0 deletions changelogs/fragments/45-ee.yml
Original file line number Diff line number Diff line change
@@ -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)."
3 changes: 3 additions & 0 deletions meta/execution-environment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
version: 1
dependencies: {}
13 changes: 13 additions & 0 deletions tests/ee/all.yml
Original file line number Diff line number Diff line change
@@ -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 }}"
48 changes: 48 additions & 0 deletions tests/ee/roles/smoke/library/smoke_ipaddress.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-

# (c) 2022 Felix Fontein <[email protected]>
# 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
25 changes: 25 additions & 0 deletions tests/ee/roles/smoke/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -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'"
1 change: 1 addition & 0 deletions tests/sanity/ignore-2.10.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions tests/sanity/ignore-2.11.txt
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions tests/sanity/ignore-2.12.txt
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions tests/sanity/ignore-2.13.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tests/ee/roles/smoke/library/smoke_ipaddress.py shebang
1 change: 1 addition & 0 deletions tests/sanity/ignore-2.14.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tests/ee/roles/smoke/library/smoke_ipaddress.py shebang
1 change: 1 addition & 0 deletions tests/sanity/ignore-2.9.txt
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit e8adbe9

Please sign in to comment.