diff options
author | 2019-02-22 16:10:27 +0100 | |
---|---|---|
committer | 2019-03-06 15:28:18 +0100 | |
commit | 22bb23fec60f2cb553e4ca2b02d67c0a3cbdfa3c (patch) | |
tree | fbf200593f2aa00c2dac2d4a350f099abafd6861 | |
parent | 0bbfd4a1be02da876c0c0dfea0f143799f1f2460 (diff) |
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
-rw-r--r-- | ansible/roles/package-repository/defaults/main.yml | 8 | ||||
-rw-r--r-- | ansible/roles/package-repository/tasks/main.yml | 42 |
2 files changed, 42 insertions, 8 deletions
diff --git a/ansible/roles/package-repository/defaults/main.yml b/ansible/roles/package-repository/defaults/main.yml index ea5796df..678b6bd4 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 686310e4..4949345a 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 |