summaryrefslogtreecommitdiffstats
path: root/ansible/roles/package-repository/tasks/main.yml
blob: 599e105201f081f4dba5828f1bf8129bb6074969 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
---
- name: Setup resolv.conf for node to find package repository by name from infra
  lineinfile:
    line: "nameserver {{ hostvars[groups.infrastructure[0]].cluster_ip }}"
    path: /etc/resolv.conf
    state: present
    insertbefore: BOF

- 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: true
        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"

- name: Add application offline package repository
  yum_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 }}"