Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for RHN download #104

Merged
merged 1 commit into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions requirements.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
collections:
- name: ansible.posix
- name: middleware_automation.common
3 changes: 3 additions & 0 deletions roles/amq_streams_common/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
---
amq_streams_common_product_version: 3.6.0
amq_streams_common_rhn_product_version: 2.5.1
amq_streams_common_rhn_home_dir: kafka_2.13-3.5.0.redhat-00014
amq_streams_common_rhn_product_category: 'jboss.amq.streams'
amq_streams_common_scala_version: 2.13
amq_streams_common_version: "{{ amq_streams_common_scala_version }}-{{ amq_streams_common_product_version }}"
amq_streams_common_archive_file: "kafka_{{ amq_streams_common_version }}.tgz"
Expand Down
12 changes: 10 additions & 2 deletions roles/amq_streams_common/tasks/install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,19 @@
- name: "Download artifacts (if required)."
ansible.builtin.include_tasks: download.yml
when:
- not amq_streams_common_redhat_enabled is defined or not amq_streams_common_redhat_enabled
- not amq_streams_common_offline_install is defined or not amq_streams_common_offline_install

- name: "Load metadata on {{ amq_streams_common_install_dir }}."
- name: "Download archive from RHN"
ansible.builtin.include_tasks: rhn/main.yml
when:
- amq_streams_common_redhat_enabled is defined and amq_streams_common_redhat_enabled
- not amq_streams_common_offline_install is defined or not amq_streams_common_offline_install
- rhn_username is defined and rhn_password is defined

- name: "Load metadata on {{ amq_streams_common_home }}."
ansible.builtin.stat:
path: "{{ amq_streams_common_install_dir }}/{{ amq_streams_common_subdir | default('bin') }}"
path: "{{ amq_streams_common_home }}/{{ amq_streams_common_subdir | default('bin') }}"
register: download_target

- name: "Extract artifact to {{ amq_streams_common_install_dir }}"
Expand Down
35 changes: 35 additions & 0 deletions roles/amq_streams_common/tasks/rhn/download.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
- name: "Ensure required parameters are provided"
ansible.builtin.assert:
that:
- rhn_username is defined and rhn_username | length > 0
- rhn_password is defined and rhn_password | length > 0
- rhn_product_id is defined and rhn_product_id | length > 0
- rhn_product_path is defined and rhn_product_path | length > 0
quiet: True

- name: "Load metadata on target location for download ({{ rhn_product_path }})"
ansible.builtin.stat:
path: "{{ rhn_product_path | dirname }}"
register: rhn_product_path_metadata
delegate_to: localhost
become: "{{ rhn_download_become | default(False) }}"

- name: "Ensure {{ rhn_product_path }} is accessible"
ansible.builtin.assert:
that:
- rhn_product_path_metadata is defined and rhn_product_path_metadata.stat is defined
- rhn_product_path_metadata.stat.writeable is defined and rhn_product_path_metadata.stat.writeable
quiet: True
fail_msg: "Path for download product is not writeable on the Ansible controller: {{ rhn_product_path }}."

- name: "Download Red Hat product into {{ rhn_product_path }} (rhn_download_become: {{ rhn_download_become }})"
middleware_automation.common.product_download: # noqa risky-file-permissions delegated, uses controller host user
client_id: "{{ rhn_username }}"
client_secret: "{{ rhn_password }}"
product_id: "{{ rhn_product_id }}"
dest: "{{ rhn_product_path }}"
no_log: "{{ omit_rhn_output | default(true) }}"
delegate_to: localhost
run_once: yes
become: "{{ rhn_download_become | default(False) }}"
55 changes: 55 additions & 0 deletions roles/amq_streams_common/tasks/rhn/latest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
---
- name: "Automate AMQ Streams install"
hosts: all
vars:
rhn_product_version: 2.5.1
rhn_product_path_pattern: '^.*/amq-streams-[0-9.]*-bin.zip$'
# Topic Management
amq_streams_broker_topics:
- name: sampleTopic
partitions: 2
replication_factor: 1
- name: otherTopic
partitions: 4
replication_factor: 1
tasks:
- name: "Ensure AMQ Streams Broker is running and available."
ansible.builtin.include_role:
name: amq_streams_common
tasks_from: rhn/search.yml
vars:
rhn_product_type: 'DISTRIBUTION'
rhn_product_category: 'jboss.amq.streams'

- ansible.builtin.debug:
var: rhn_products.results

- name: Determine patch versions list
ansible.builtin.set_fact:
filtered_versions: "{{ rhn_products.results | map(attribute='file_path') | select('match', rhn_product_path_pattern) | map('regex_replace','[^/]*/amq-streams-([0-9]*[.][0-9]*[.][0-9]*)-.*','\\1' ) | list | unique }}"
delegate_to: localhost
run_once: yes

- name: Determine latest version
ansible.builtin.set_fact:
rhn_product_latest_version: "{{ filtered_versions | middleware_automation.common.version_sort | last }}"
delegate_to: localhost
run_once: yes

- ansible.builtin.debug:
var: rhn_product_latest_version

- name: "TODO"
ansible.builtin.set_fact:
rhn_filtered_products: "{{ rhn_products.results | selectattr('file_path', 'match', '^.*/amq-streams-[0-9.]*-bin.zip$') }}"

- ansible.builtin.debug:
var: rhn_filtered_products

- name: "Download "
ansible.builtin.include_role:
name: amq_streams_common
tasks_from: rhn/download.yml
vars:
rhn_product_id: "{{ rhn_filtered_products[0].id }}"
rhn_product_path: /tmp/
32 changes: 32 additions & 0 deletions roles/amq_streams_common/tasks/rhn/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
- name: "Ensure required parameters are provided."
ansible.builtin.assert:
that:
- amq_streams_common_download_dir is defined
quiet: true

- name: "Search RHN artefact for {{ amq_streams_common_rhn_product_version }}."
ansible.builtin.include_role:
name: amq_streams_common
tasks_from: rhn/search.yml
vars:
rhn_product_type: 'DISTRIBUTION'
rhn_product_category: "{{ amq_streams_common_rhn_product_category }}"
rhn_product_version: "{{ amq_streams_common_rhn_product_version }}" #"{{ amq_version.split('.')[:2] | join('.') }}"

- name: "Determine which archive to download"
ansible.builtin.set_fact:
rhn_filtered_products: "{{ rhn_products.results | selectattr('file_path', 'match', '^.*/amq-streams-[0-9.]*-bin.zip$') }}"

- name: "Download rhn_filtered_products[0]"
ansible.builtin.include_role:
name: amq_streams_common
tasks_from: rhn/download.yml
vars:
rhn_product_id: "{{ rhn_filtered_products[0].id }}"
rhn_product_path: "{{ amq_streams_common_download_dir }}"

- name: "XXX"
ansible.builtin.set_fact:
amq_streams_common_archive_file: "amq-streams-{{ amq_streams_common_rhn_product_version }}-bin.zip"
amq_streams_common_home: "{{ amq_streams_common_install_dir }}/{{ amq_streams_common_rhn_home_dir }}"
32 changes: 32 additions & 0 deletions roles/amq_streams_common/tasks/rhn/search.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
- name: "Ensure required parameters are provided"
ansible.builtin.assert:
that:
- rhn_username is defined and rhn_username | length > 0
- rhn_password is defined and rhn_password | length > 0
- rhn_product_category is defined and rhn_product_category | length > 0
- rhn_product_type is defined
- rhn_product_version is defined and rhn_product_version | length > 0
- rhn_product_type == 'BUGFIX' or rhn_product_type == 'DISTRIBUTION'
quiet: True

- name: Retrieve product download using JBossNetwork API
middleware_automation.common.product_search:
client_id: "{{ rhn_username }}"
client_secret: "{{ rhn_password }}"
product_type: "{{ rhn_product_type }}"
product_version: "{{ rhn_product_version }}"
product_category: "{{ rhn_product_category }}"
register: rhn_products
no_log: "{{ omit_rhn_output | default(true) }}"
delegate_to: localhost
become: "{{ rhn_download_become | default(False) }}"
run_once: yes

- name: "Ensure search results are valid."
ansible.builtin.assert:
that:
- rhn_products is defined
- rhn_products.results is defined
quiet: True
fail_msg: "Invalid results returned: {{ rhn_products }}"
Loading