Skip to content

Commit

Permalink
Refactored repository role, changes for RHEL hitachienergy#536
Browse files Browse the repository at this point in the history
  • Loading branch information
to-bar committed Oct 2, 2019
1 parent 34522ea commit 4a8fc8e
Show file tree
Hide file tree
Showing 31 changed files with 110 additions and 93 deletions.
2 changes: 1 addition & 1 deletion core/src/epicli/cli/engine/PrepareEngine.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@


class PrepareEngine(Step):
PREPARE_PATH = DATA_FOLDER_PATH + '/common/ansible/playbooks/roles/repository/files/prepare'
PREPARE_PATH = DATA_FOLDER_PATH + '/common/ansible/playbooks/roles/repository/files/download-requirements'

def __init__(self, input_data):
super().__init__(__name__)
Expand Down
4 changes: 2 additions & 2 deletions core/src/epicli/cli/engine/ansible/AnsibleRunner.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def run(self):
self.logger.info('Setting up repository for cluster provisioning. This will take a while...')
repository_setup_play_result = self.ansible_command.run_playbook_with_retries(
inventory=inventory_path,
playbook_path=self.playbook_path('repository-setup'),
playbook_path=self.playbook_path('repository_setup'),
retries=5)

if repository_setup_play_result != 0:
Expand All @@ -84,7 +84,7 @@ def run(self):

repository_teardown_play_result = self.ansible_command.run_playbook_with_retries(
inventory=inventory_path,
playbook_path=self.playbook_path('repository-teardown'),
playbook_path=self.playbook_path('repository_teardown'),
retries=1)

if repository_teardown_play_result != 0:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
#!/bin/bash
#!/bin/bash -eu

REPOSITORY_URL=$1

curl -I -L $REPOSITORY_URL | grep "HTTP/1.1 200 OK"

# Todo: remove if unnecessary
#sed -i -e "s/enabled=1/enabled=0/g" /etc/yum.repos.d/*.repo;

cat << EOF > /etc/yum.repos.d/epirepo.repo
[epirepo]
name=epirepo
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash -eu

ENABLED_REPOS_FILE=/tmp/enabled-system-repos.txt

if [ ! -f "$ENABLED_REPOS_FILE" ]; then
yum repolist -v enabled | grep -i Repo-id | awk -F ":" '{print $2}' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' | awk -F "/" '{print $1}' > $ENABLED_REPOS_FILE
fi
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash -eu

yum-config-manager --disable epirepo
yum makecache
yum repolist
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash -eu

REPOS_LIST_FILE=/tmp/enabled-system-repos.txt

cat $REPOS_LIST_FILE | while read repository
do
echo "Disabling repository: $repository"
yum-config-manager --disable $repository
done

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash -eu

REPOS_LIST_FILE=/tmp/enabled-system-repos.txt

cat $REPOS_LIST_FILE | while read repository
do
echo "Enabling repository: $repository"
yum-config-manager --enable $repository
done

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash -eu

EPI_REPO_SERVER_PATH=$1 # /var/www/html/epirepo is the default
IS_OFFLINE_MODE=$2

if $IS_OFFLINE_MODE = true; then
yum install -y $(ls $EPI_REPO_SERVER_PATH/packages/offline_prereqs/*.rpm) #TODO: to test
else
yum install -y httpd createrepo yum-utils
fi

setenforce 0
systemctl start httpd

createrepo $EPI_REPO_SERVER_PATH/packages
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash -eu

systemctl stop httpd
systemctl disable httpd
Original file line number Diff line number Diff line change
@@ -1,15 +1,31 @@
---
# download-requirements-done.flag file is used to avoid re-downloading requirements (to save time)
# this is to be optimized in the future

- name: Check if flag file exists
stat:
path: /tmp/epi-download-requirements/download-requirements-done.flag
register: stat_result

- name: Remove download-requirements-done.flag file if expired
file:
path: /tmp/epi-download-requirements/download-requirements-done.flag
state: absent
when:
- stat_result.stat.exists
- (ansible_date_time.epoch|int - stat_results.stat.mtime) > 3600 # older than 1h

- name: Check whether to run download script
stat:
path: /tmp/epi-download-requirements/download-requirements-done.flag
register: stat_result

- name: Run download-requirements script, it can take a long time
shell: /tmp/epi-download-requirements/download-requirements.sh /var/www/html/epirepo
when: stat_result.stat.exists == False
when: not stat_result.stat.exists

- name: Create flag file to not re-download requirements next time
file:
path: /tmp/epi-download-requirements/download-requirements-done.flag
state: touch
when: stat_result.stat.exists == False
when: not stat_result.stat.exists
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
/tmp/epi-repository-setup-scripts/create-repository.sh /var/www/html/epirepo {{ offline_mode }} |&
tee /tmp/epi-repository-setup-scripts/create-repository.log
when:
- groups['kubernetes_master'][0] == inventory_hostname
- not custom_repository_url
- inventory_hostname in groups['repository']

- name: Disable system repositories and setup epirepo
- name: Disable system repositories and set up epirepo
block:
- name: Create active repositories list
shell: /tmp/epi-repository-setup-scripts/create-enabled-system-repositories-list.sh
- name: Disable active system repositories
- name: Create list of enabled repositories
shell: /tmp/epi-repository-setup-scripts/create-enabled-system-repos-list.sh
- name: Disable system repositories
shell: /tmp/epi-repository-setup-scripts/disable-system-repos.sh
- name: Setup epirepo on clients
- name: Add and enable epirepo
shell: >-
/tmp/epi-repository-setup-scripts/setup-epirepo-client.sh {{ repository_url }} |&
tee /tmp/epi-repository-setup-scripts/setup-epirepo-client.log
/tmp/epi-repository-setup-scripts/add-epirepo-client.sh {{ repository_url }} |&
tee /tmp/epi-repository-setup-scripts/add-epirepo-client.log
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
- name: Set mode
set_fact:
offline_mode: "{{ offline_requirements | length | bool }}"
offline_mode: "{{ offline_requirements | length > 0 }}"

- name: Print mode
debug:
Expand All @@ -23,7 +23,7 @@

- name: Copy files for downloading requirements to repository host
copy:
src: "prepare/{{ download_script_subdir }}/"
src: "download-requirements/{{ download_script_subdir }}/"
dest: /tmp/epi-download-requirements

- name: Copy skopeo binary to repository host
Expand All @@ -42,23 +42,33 @@

when:
- not offline_mode
- groups['kubernetes_master'][0] == inventory_hostname #TODO: dedicated host for repository in Ansible inventory
- not custom_repository_url
- inventory_hostname in groups['repository']

- name: Copy repository configuration scripts
- name: Copy repository client configuration scripts
copy:
src: "repository/{{ ansible_os_family }}/"
src: "client/{{ ansible_os_family }}/"
dest: "/tmp/epi-repository-setup-scripts"
mode: a+x

- name: Copy requirements for offline installation (epi-repo) to repository host
- name: Copy repository server configuration scripts
copy:
src: /shared/epi-repo/ #TODO: This needs to be configurable
dest: /var/www/html/epi-repo
src: "server/{{ ansible_os_family }}/"
dest: "/tmp/epi-repository-setup-scripts"
mode: a+x
when:
- not offline_mode
- not custom_repository_url
- inventory_hostname in groups['repository']

- name: Copy requirements for offline installation to repository host
copy:
src: "{{ offline_requirements }}/" #TODO: handle case with double slash
dest: /var/www/html/epirepo
when:
- offline_mode
- groups['kubernetes_master'][0] == inventory_hostname
- not custom_repository_url
- inventory_hostname in groups['repository']

- name: Configure repository and clients
- name: Set up repositories
include_tasks: "setup-{{ ansible_os_family }}.yml"
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
---
- name: Re-enable system repositories
shell: /tmp/epi-repository-setup-scripts/enable-system-repos.sh

- name: Enable system repositories and disable epirepo for offline mode
block:
- name: Enable system repositories
shell: /tmp/{{ ansible_os_family }}/enable-system-repos.sh
- name: Disable epirepo on clients
shell: /tmp/{{ ansible_os_family }}/disable-epirepo-client-rh.sh
when:
- offline_mode == true
- name: Disable epirepo
shell: /tmp/epi-repository-setup-scripts/disable-epirepo-client.sh

- name: Disable system repositories and setup epirepo for online mode
block:
- name: Enable system repositories
shell: /tmp/{{ ansible_os_family }}/enable-system-repos.sh
- name: Disable epirepo on clients
shell: /tmp/{{ ansible_os_family }}/disable-epirepo-client-rh.sh
- name: Disable epirepo server
shell: /tmp/epi-repository-setup-scripts/disable-repository-server.sh
when:
- not groups['kubernetes_master'][0] == inventory_hostname
- offline_mode == false
- not custom_repository_url
- inventory_hostname in groups['repository']
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
- name: Configure repository and clients
include_tasks: "teardown-{{ ansible_os_family }}.yml"
- name: Re-enable system repositories and disable epirepo
include_tasks: teardown-{{ ansible_os_family }}.yml

0 comments on commit 4a8fc8e

Please sign in to comment.