From 22bb23fec60f2cb553e4ca2b02d67c0a3cbdfa3c Mon Sep 17 00:00:00 2001 From: Bartek Grzybowski Date: Fri, 22 Feb 2019 16:10:27 +0100 Subject: 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 Change-Id: Id5e81e9d60d15393d5d2e12aef3da476a3b0d4c3 --- ansible/roles/package-repository/defaults/main.yml | 8 ++++- ansible/roles/package-repository/tasks/main.yml | 42 ++++++++++++++++++---- 2 files changed, 42 insertions(+), 8 deletions(-) (limited to 'ansible/roles/package-repository') 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 -- cgit 1.2.3-korg