From 305b0a3def025530430d20fedd4c7ee7f89170fd Mon Sep 17 00:00:00 2001 From: Eamon Tracey <66919574+EamonTracey@users.noreply.github.com> Date: Thu, 20 Jul 2023 09:34:44 -0400 Subject: [PATCH] add new CI workflow to test against the automation hub collection (#1795) * add new CI workflow to test against the automation hub collection * remove installation of docker-compose * add changelog Issue: AAH-2419 Signed-off-by: EamonTracey --- .../ci_automation_hub_collection.yml | 60 ++++++++++ CHANGES/2419.misc | 1 + dev/ah_collection_plays/content.yml | 89 +++++++++++++++ dev/ah_collection_plays/ee.yml | 60 ++++++++++ dev/ah_collection_plays/repo.yml | 44 +++++++ dev/ah_collection_plays/user.yml | 107 ++++++++++++++++++ dev/ah_collection_plays/vars.yml | 5 + 7 files changed, 366 insertions(+) create mode 100644 .github/workflows/ci_automation_hub_collection.yml create mode 100644 CHANGES/2419.misc create mode 100644 dev/ah_collection_plays/content.yml create mode 100644 dev/ah_collection_plays/ee.yml create mode 100644 dev/ah_collection_plays/repo.yml create mode 100644 dev/ah_collection_plays/user.yml create mode 100644 dev/ah_collection_plays/vars.yml diff --git a/.github/workflows/ci_automation_hub_collection.yml b/.github/workflows/ci_automation_hub_collection.yml new file mode 100644 index 0000000000..0f8394a4a2 --- /dev/null +++ b/.github/workflows/ci_automation_hub_collection.yml @@ -0,0 +1,60 @@ +--- +name: Automation Hub Collection CI +on: + pull_request: + branches: + - "*" + paths-ignore: + - "CHANGES/**" + - "docs/**" + - "mkdocs.yml" + push: + branches: + - "*" + workflow_dispatch: + +jobs: + automation_hub_collection: + runs-on: ubuntu-latest + steps: + - name: Checkout galaxy_ng + uses: actions/checkout@v3 + + - name: Setup python + uses: actions/setup-python@v2 + with: + python-version: "3.10" + + - name: Checkout the automation hub collection + uses: actions/checkout@v3 + with: + repository: ansible/automation_hub_collection + path: automation_hub_collection + + - name: Build and install the collection + working-directory: automation_hub_collection + run: | + ansible all -i localhost, -c local -m template -a "src=galaxy.yml.j2 dest=galaxy.yml" -e collection_namespace=ansible -e collection_name=automation_hub -e collection_version=1.0.0 -e collection_repo=https://github.com/ansible/automation_hub_collection + ansible-galaxy collection build -vvv + ansible-galaxy collection install ansible-automation_hub-1.0.0.tar.gz -vvv + + - name: Spin up a standalone galaxy_ng installation + run: | + echo "COMPOSE_PROFILE=standalone" > .compose.env + echo "DEV_SOURCE_PATH=galaxy_ng" >> .compose.env + make docker/all + ./compose up -d + pip3 install --upgrade requests pyyaml + python3 dev/common/poll.py + + - name: Test the user playbook + run: ansible-playbook dev/ah_collection_plays/user.yml -vvv + + - name: Test the content playbook + run: ansible-playbook dev/ah_collection_plays/content.yml -vvv + + - name: Test the repo playbook + run: ansible-playbook dev/ah_collection_plays/repo.yml -vvv + + - name: Test the ee playbook + run: ansible-playbook dev/ah_collection_plays/ee.yml -vvv diff --git a/CHANGES/2419.misc b/CHANGES/2419.misc new file mode 100644 index 0000000000..80bbf748bb --- /dev/null +++ b/CHANGES/2419.misc @@ -0,0 +1 @@ +New CI workflow to test against the automation hub collection diff --git a/dev/ah_collection_plays/content.yml b/dev/ah_collection_plays/content.yml new file mode 100644 index 0000000000..83d2498397 --- /dev/null +++ b/dev/ah_collection_plays/content.yml @@ -0,0 +1,89 @@ +--- +- name: Galaxy + AH Collection Tests for Content Automation + hosts: localhost + connection: local + gather_facts: false + collections: + - ansible.automation_hub + + pre_tasks: + - name: Include variables + ansible.builtin.include_vars: + file: vars.yml + + tasks: + - name: Authenticate and retrieve API token + ansible.automation_hub.ah_token: + ah_host: "{{ ah_host }}" + ah_username: "{{ ah_username }}" + ah_password: "{{ ah_password }}" + ah_path_prefix: "{{ ah_path_prefix }}" + + - name: Create the automate namespace + ansible.automation_hub.ah_namespace: + name: automate + company: Automator Inc. + email: automator@redhat.com + description: The namespace for all things automation + ah_host: "{{ ah_host }}" + ah_token: "{{ ah_token }}" + ah_path_prefix: "{{ ah_path_prefix }}" + + - name: Rename automate namespace to automator + ansible.automation_hub.ah_namespace: + name: automate + new_name: automator + ah_host: "{{ ah_host }}" + ah_token: "{{ ah_token }}" + ah_path_prefix: "{{ ah_path_prefix }}" + + - name: Delete the automator namespace + ansible.automation_hub.ah_namespace: + state: absent + name: automator + ah_host: "{{ ah_host }}" + ah_token: "{{ ah_token }}" + ah_path_prefix: "{{ ah_path_prefix }}" + + - name: Ensure there is an ansible namespace + ansible.automation_hub.ah_namespace: + name: ansible + ah_host: "{{ ah_host }}" + ah_token: "{{ ah_token }}" + ah_path_prefix: "{{ ah_path_prefix }}" + + - name: Upload the automation hub collection to the ansible namespace + ansible.automation_hub.ah_collection: + namespace: ansible + name: automation_hub + path: "{{ ah_artifact_runner_absolute_path }}" + version: "1.0.0" + ah_host: "{{ ah_host }}" + ah_token: "{{ ah_token }}" + ah_path_prefix: "{{ ah_path_prefix }}" + + - name: Approve the automation hub collection + ansible.automation_hub.ah_approval: + namespace: ansible + name: automation_hub + version: "1.0.0" + ah_host: "{{ ah_host }}" + ah_token: "{{ ah_token }}" + ah_path_prefix: "{{ ah_path_prefix }}" + + - name: Delete the automation hub collection + ansible.automation_hub.ah_collection: + state: absent + namespace: ansible + name: automation_hub + version: "1.0.0" + ah_host: "{{ ah_host }}" + ah_token: "{{ ah_token }}" + ah_path_prefix: "{{ ah_path_prefix }}" + + - name: Deauthenticate + ansible.automation_hub.ah_token: + state: absent + ah_host: "{{ ah_host }}" + ah_token: "{{ ah_token }}" + ah_path_prefix: "{{ ah_path_prefix }}" diff --git a/dev/ah_collection_plays/ee.yml b/dev/ah_collection_plays/ee.yml new file mode 100644 index 0000000000..27d1e7e843 --- /dev/null +++ b/dev/ah_collection_plays/ee.yml @@ -0,0 +1,60 @@ +--- +- name: Galaxy + AH Collection Tests for Execution Environment Automation + hosts: localhost + connection: local + gather_facts: false + collections: + - ansible.automation_hub + + pre_tasks: + - name: Include variables + ansible.builtin.include_vars: + file: vars.yml + + tasks: + - name: Add redhat.io registry + ansible.automation_hub.ah_ee_registry: + name: redhat + url: registry.redhat.io + ah_host: "{{ ah_host }}" + ah_username: "{{ ah_username }}" + ah_password: "{{ ah_password }}" + ah_path_prefix: "{{ ah_path_prefix }}" + + - name: Index redhat.io registry + ansible.automation_hub.ah_ee_registry_index: + name: redhat + ah_host: "{{ ah_host }}" + ah_username: "{{ ah_username }}" + ah_password: "{{ ah_password }}" + ah_path_prefix: "{{ ah_path_prefix }}" + + - name: Update aap22ee29rhel8 ee repository + ansible.automation_hub.ah_ee_repository: + name: ansible-automation-platform-22/ee-29-rhel8 + description: AAP RHEL execution environment + readme: | + # RHEL execution environment + * Contains ansible + ah_host: "{{ ah_host }}" + ah_username: "{{ ah_username }}" + ah_password: "{{ ah_password }}" + ah_path_prefix: "{{ ah_path_prefix }}" + + - name: Delete the aap22ee29rhel8 repository + ansible.automation_hub.ah_ee_repository: + name: ansible-automation-platform-22/ee-29-rhel8 + state: absent + ah_host: "{{ ah_host }}" + ah_username: "{{ ah_username }}" + ah_password: "{{ ah_password }}" + ah_path_prefix: "{{ ah_path_prefix }}" + + - name: Delete the redhat.io registry + ansible.automation_hub.ah_ee_registry: + name: redhat + state: absent + ah_host: "{{ ah_host }}" + ah_username: "{{ ah_username }}" + ah_password: "{{ ah_password }}" + ah_path_prefix: "{{ ah_path_prefix }}" diff --git a/dev/ah_collection_plays/repo.yml b/dev/ah_collection_plays/repo.yml new file mode 100644 index 0000000000..d01b20cfb8 --- /dev/null +++ b/dev/ah_collection_plays/repo.yml @@ -0,0 +1,44 @@ +--- +- name: Galaxy + AH Collection Tests for Repo Automation + hosts: localhost + connection: local + gather_facts: false + collections: + - ansible.automation_hub + + pre_tasks: + - name: Include variables + ansible.builtin.include_vars: + file: vars.yml + + tasks: + - name: Authenticate and retrieve API token + ansible.automation_hub.ah_token: + ah_host: "{{ ah_host }}" + ah_username: "{{ ah_username }}" + ah_password: "{{ ah_password }}" + ah_path_prefix: "{{ ah_path_prefix }}" + + - name: Configure community repository + ansible.automation_hub.ah_repository: + name: community + url: https://galaxy.ansible.com/api/ + requirements: + - community.docker + - geerlingguy.k8s + ah_host: "{{ ah_host }}" + ah_token: "{{ ah_token }}" + ah_path_prefix: "{{ ah_path_prefix }}" + + - name: Sync community repository + ansible.automation_hub.ah_repository_sync: + name: community + ah_host: "{{ ah_host }}" + ah_token: "{{ ah_token }}" + ah_path_prefix: "{{ ah_path_prefix }}" + + - name: Deauthenticate + ansible.automation_hub.ah_token: + ah_host: "{{ ah_host }}" + ah_token: "{{ ah_token }}" + ah_path_prefix: "{{ ah_path_prefix }}" diff --git a/dev/ah_collection_plays/user.yml b/dev/ah_collection_plays/user.yml new file mode 100644 index 0000000000..23b80f21dd --- /dev/null +++ b/dev/ah_collection_plays/user.yml @@ -0,0 +1,107 @@ +--- +- name: Galaxy + AH Collection Tests for User Automation + hosts: localhost + connection: local + gather_facts: false + collections: + - ansible.automation_hub + + pre_tasks: + - name: Include variables + ansible.builtin.include_vars: + file: vars.yml + + tasks: + - name: Create a developers group + ansible.automation_hub.ah_group: + name: developers + ah_host: "{{ ah_host }}" + ah_username: "{{ ah_username }}" + ah_password: "{{ ah_password }}" + ah_path_prefix: "{{ ah_path_prefix }}" + + - name: Add 3 new users who are developers + ansible.automation_hub.ah_user: + username: "dev_{{ item }}" + password: password!@3w6$% + first_name: Developer + last_name: "{{ item | capitalize }}" + groups: + - developers + ah_host: "{{ ah_host }}" + ah_username: "{{ ah_username }}" + ah_password: "{{ ah_password }}" + ah_path_prefix: "{{ ah_path_prefix }}" + loop: + - red + - green + - blue + + - name: Create an executives group + ansible.automation_hub.ah_group: + name: executives + ah_host: "{{ ah_host }}" + ah_username: "{{ ah_username }}" + ah_password: "{{ ah_password }}" + ah_path_prefix: "{{ ah_path_prefix }}" + + - name: Create an omnipotent role with all permissions + ansible.automation_hub.ah_role: + name: galaxy.omnipotent + description: Manage anything and everything + perms: all + ah_host: "{{ ah_host }}" + ah_username: "{{ ah_username }}" + ah_password: "{{ ah_password }}" + ah_path_prefix: "{{ ah_path_prefix }}" + +# TODO: Add a test that permissions/roles can be added to a group after +# https://github.com/ansible/automation_hub_collection/issues/179 is resolved. + + - name: Create new executive users + ansible.automation_hub.ah_user: + username: "{{ item }}" + password: executive!@3w6$% + is_superuser: true + email: "{{ item }}@redhat.com" + groups: + - executives + - developers + ah_host: "{{ ah_host }}" + ah_username: "{{ ah_username }}" + ah_password: "{{ ah_password }}" + ah_path_prefix: "{{ ah_path_prefix }}" + loop: + - ceo + - cfo + - cto + + - name: Delete the red developer + ansible.automation_hub.ah_user: + state: absent + username: dev_red + ah_host: "{{ ah_host }}" + ah_username: "{{ ah_username }}" + ah_password: "{{ ah_password }}" + ah_path_prefix: "{{ ah_path_prefix }}" + + - name: Delete the developers and executives groups + ansible.automation_hub.ah_group: + state: absent + name: "{{ item }}" + ah_host: "{{ ah_host }}" + ah_username: "{{ ah_username }}" + ah_password: "{{ ah_password }}" + ah_path_prefix: "{{ ah_path_prefix }}" + loop: + - developers + - executives + + - name: Delete the omnipotent role + ansible.automation_hub.ah_role: + state: absent + name: galaxy.omnipotent + ah_host: "{{ ah_host }}" + ah_username: "{{ ah_username }}" + ah_password: "{{ ah_password }}" + ah_path_prefix: "{{ ah_path_prefix }}" diff --git a/dev/ah_collection_plays/vars.yml b/dev/ah_collection_plays/vars.yml new file mode 100644 index 0000000000..3f11129e14 --- /dev/null +++ b/dev/ah_collection_plays/vars.yml @@ -0,0 +1,5 @@ +ah_host: http://localhost:5001 +ah_username: iqe_admin +ah_password: redhat +ah_path_prefix: automation-hub +ah_artifact_runner_absolute_path: /home/runner/work/galaxy_ng/galaxy_ng/automation_hub_collection/ansible-automation_hub-1.0.0.tar.gz