summaryrefslogtreecommitdiffstats
path: root/roles/ands_kaas/tasks/volume.yml
blob: 2c695f2b510ba3f55212a83b4ff324de302d4041 (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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
---
- name: "Configure {{ name }} fact"
  set_fact: "kaas_{{ name }}_path={{ path }}"

- name: "Configure {{ name }} fact"
  set_fact: "kaas_{{ name }}_hostpath={{ hostpath }}"

- name: "Ensure {{ path }} exists"
  file: 
    path: "{{ path }}" 
    state: "directory" 
    recurse: "no"
  register: mkdir
  
- name: "Ensure the {{ path }} is writeable by project pods"
  vars: 
    default_group: "{{ kaas_openshift_gid_ranges[kaas_project] | default('') | regex_replace('^([0-9]+)[^0-9]*.*$', '\\1') }}"
  file: 
    path: "{{ path }}" 
    state: "directory" 
    recurse: "no"
    mode: "{{ volume.mode | default(02775) }}" 
    owner: "{{ volume.owner | default(kaas_project_config.file_owner) | default(kaas_default_file_owner) }}" 
    group: "{{ volume.group | default(kaas_project_config.file_group) | default(default_group) }}"
  register: chmod
  when:
    - mkdir | changed
    - kaas_openshift_gid_ranges[kaas_project] is defined
    - osvpath[:1] != "/"

# There is no other way to write for users. There will be just two osv's one writeable and one not. 
# We may create a dir with the wrong one and have permissions not set
#    - volume.write | default(false)

- name: "Setting default permissions for non standard locations"
  file: 
    path: "{{ path }}" 
    state: "directory" 
    recurse: "no"
    mode: "{{ volume.mode | default(0755) }}" 
    owner: "{{ volume.owner | default(kaas_project_config.file_owner) | default(kaas_default_file_owner) }}" 
    group: "{{ volume.group | default(kaas_project_config.file_group) | default(kaas_default_file_group) }}"
  when: 
    - mkdir | changed
    - chmod | skipped
    
- name: "Setting SELinux context for non standard locations"
  sefcontext: target="{{ hostpath }}" setype="svirt_sandbox_file_t" state="present" reload="yes"
  when: 
    - mkdir | changed
    - chmod | skipped
    - voltype[0] == "host"

- name: "Apply SELinux context for non standard locations"
  shell: restorecon "{{ hostpath }}" 
  when: 
    - mkdir | changed
    - chmod | skipped
    - voltype[0] == "host"