Disable all default repositories
This patch allows configuring multiple repositories
via 'package_repositories' dict. It also disables
all default repositories not to break 'yum' operation
in environment without route to Internet.
Issue-ID: OOM-1632
Signed-off-by: Bartek Grzybowski <b.grzybowski@partner.samsung.com>
Change-Id: Id5e81e9d60d15393d5d2e12aef3da476a3b0d4c3
diff --git a/ansible/roles/package-repository/defaults/main.yml b/ansible/roles/package-repository/defaults/main.yml
index ea5796d..678b6bd 100644
--- a/ansible/roles/package-repository/defaults/main.yml
+++ b/ansible/roles/package-repository/defaults/main.yml
@@ -1,2 +1,8 @@
---
-deploy_package_repository: true
+package_repositories:
+ - name: "{{ app_name }}"
+ file: "{{ app_name | lower }}"
+ description: "{{ app_name | upper }} offline repository"
+ baseurl: "{{ 'http://repo.infra-server/rhel' if 'infrastructure' not in group_names else 'file://' + app_data_path + '/pkg/rhel' }}"
+ gpgcheck: false
+ enabled: true
diff --git a/ansible/roles/package-repository/tasks/main.yml b/ansible/roles/package-repository/tasks/main.yml
index 686310e..4949345 100644
--- a/ansible/roles/package-repository/tasks/main.yml
+++ b/ansible/roles/package-repository/tasks/main.yml
@@ -7,13 +7,41 @@
insertbefore: BOF
become: true
+- name: Disable all OS default repositories
+ block:
+ - name: Find repo files names
+ find:
+ paths: /etc/yum.repos.d
+ pattern: '*.repo'
+ register: repo_files
+
+ - name: Get all defined offline repo names
+ set_fact: package_repositories_names="{{ package_repositories | selectattr('name', 'defined') | map(attribute='name') | list }}"
+
+ - name: Backup repo files
+ copy:
+ remote_src: yes
+ src: "{{ item.path }}"
+ dest: "{{ item.path }}.disabled"
+ loop: "{{ repo_files.files }}"
+ when: "(item.path | basename | splitext)[0] not in package_repositories_names"
+
+ - name: Remove disabled repo files
+ file:
+ path: "{{ item.path }}"
+ state: absent
+ loop: "{{ repo_files.files }}"
+ when: "(item.path | basename | splitext)[0] not in package_repositories_names"
+ become: yes
+
- name: Add application offline package repository
yum_repository:
- name: "{{ app_name }}"
- file: "{{ app_name | lower }}"
- description: "{{ app_name | upper }} offline repository"
- baseurl: "{{ 'http://repo.infra-server/rhel' if 'infrastructure' not in group_names else 'file://' + app_data_path + '/pkg/rhel' }}"
- gpgcheck: false
- enabled: true
- when: deploy_package_repository
+ name: "{{ item.name }}"
+ file: "{{ item.file }}"
+ description: "{{ item.description | default('') }}"
+ baseurl: "{{ item.baseurl | default('') }}"
+ gpgcheck: "{{ item.gpgcheck | default(true) }}"
+ enabled: "{{ item.enabled | default(false) }}"
+ state: "{{ item.state | default('present') }}"
+ loop: "{{ package_repositories }}"
become: true