|
1 | | ---- |
2 | | -- name: Check if the logging requires |
3 | | - when: not (zuul_log_collection | default(false)) |
| 1 | +- name: Ensure cifmw_basedir param is set |
| 2 | + when: |
| 3 | + - cifmw_basedir is not defined |
| 4 | + ansible.builtin.set_fact: |
| 5 | + cifmw_basedir: "{{ ansible_user_dir }}/ci-framework-data" |
| 6 | + |
| 7 | +- name: Try to load parameters files |
4 | 8 | block: |
5 | | - - name: Ensure cifmw_basedir param is set |
| 9 | + - name: Check directory availabilty |
| 10 | + register: param_dir |
| 11 | + ansible.builtin.stat: |
| 12 | + path: "{{ cifmw_basedir }}/artifacts/parameters" |
| 13 | + |
| 14 | + - name: Load parameters files |
6 | 15 | when: |
7 | | - - cifmw_basedir is not defined |
| 16 | + - param_dir.stat.exists | bool |
| 17 | + ansible.builtin.include_vars: |
| 18 | + dir: "{{ cifmw_basedir }}/artifacts/parameters" |
| 19 | + always: |
| 20 | + - name: Set custom cifmw PATH reusable fact |
| 21 | + when: |
| 22 | + - cifmw_path is not defined |
8 | 23 | ansible.builtin.set_fact: |
9 | | - cifmw_basedir: "{{ ansible_user_dir }}/ci-framework-data" |
| 24 | + cifmw_path: "{{ ansible_user_dir }}/.crc/bin:{{ ansible_user_dir }}/.crc/bin/oc:{{ ansible_user_dir }}/bin:{{ ansible_env.PATH }}" |
| 25 | + cacheable: true |
10 | 26 |
|
11 | | - - name: Try to load parameters files |
12 | | - block: |
13 | | - - name: Check directory availability |
14 | | - register: param_dir |
15 | | - ansible.builtin.stat: |
16 | | - path: "{{ cifmw_basedir }}/artifacts/parameters" |
| 27 | +- name: Set destination folder for the logs |
| 28 | + ansible.builtin.set_fact: |
| 29 | + logfiles_dest_dir: >- |
| 30 | + {{ |
| 31 | + ( |
| 32 | + cifmw_basedir | default(ansible_user_dir ~ '/ci-framework-data'), |
| 33 | + 'logs/', |
| 34 | + now(fmt='%Y-%m-%d_%H-%M') |
| 35 | + ) | path_join |
| 36 | + }} |
| 37 | +- name: Generate artifacts |
| 38 | + ansible.builtin.import_role: |
| 39 | + name: artifacts |
17 | 40 |
|
18 | | - - name: Load parameters files |
19 | | - when: |
20 | | - - param_dir.stat.exists | bool |
21 | | - ansible.builtin.include_vars: |
22 | | - dir: "{{ cifmw_basedir }}/artifacts/parameters" |
23 | | - always: |
24 | | - - name: Set custom cifmw PATH reusable fact |
25 | | - when: |
26 | | - - cifmw_path is not defined |
27 | | - ansible.builtin.set_fact: |
28 | | - cifmw_path: "{{ ansible_user_dir }}/.crc/bin:{{ ansible_user_dir }}/.crc/bin/oc:{{ ansible_user_dir }}/bin:{{ ansible_env.PATH }}" |
29 | | - cacheable: true |
| 41 | +- name: Collect container images used in the environment |
| 42 | + ansible.builtin.import_role: |
| 43 | + name: env_op_images |
30 | 44 |
|
31 | | - - name: Set destination folder for the logs |
32 | | - ansible.builtin.set_fact: |
33 | | - logfiles_dest_dir: >- |
| 45 | +- name: Create a versioned log folder |
| 46 | + ansible.builtin.file: |
| 47 | + path: "{{ logfiles_dest_dir }}" |
| 48 | + state: directory |
| 49 | + mode: "0775" |
| 50 | + |
| 51 | +- name: Return a list of log files in home directory |
| 52 | + ansible.builtin.find: |
| 53 | + paths: "{{ ansible_user_dir }}" |
| 54 | + patterns: "*.log" |
| 55 | + register: _log_files |
| 56 | + |
| 57 | +- name: Ensure ansible facts cache exists |
| 58 | + register: ansible_facts_cache_state |
| 59 | + ansible.builtin.stat: |
| 60 | + path: "{{ ansible_user_dir }}/ansible_facts_cache" |
| 61 | + |
| 62 | +- name: Copy log files |
| 63 | + when: |
| 64 | + - _log_files.matched > 0 |
| 65 | + block: |
| 66 | + - name: Copy logs to proper location |
| 67 | + ansible.builtin.copy: |
| 68 | + src: "{{ item.path }}" |
| 69 | + dest: "{{ [ logfiles_dest_dir , item.path | basename ] | path_join }}" |
| 70 | + remote_src: true |
| 71 | + mode: "0666" |
| 72 | + loop: "{{ _log_files.files }}" |
| 73 | + |
| 74 | + - name: Remove original log from home directory |
| 75 | + ansible.builtin.file: |
| 76 | + path: "{{ item.path }}" |
| 77 | + state: absent |
| 78 | + loop: "{{ _log_files.files }}" |
| 79 | + |
| 80 | +- name: Copy Ansible facts if exists |
| 81 | + when: |
| 82 | + - ansible_facts_cache_state.stat.exists is defined |
| 83 | + - ansible_facts_cache_state.stat.exists | bool |
| 84 | + block: |
| 85 | + - name: Copy facts to dated directory |
| 86 | + ansible.builtin.copy: |
| 87 | + src: "{{ ansible_user_dir }}/ansible_facts_cache" |
| 88 | + dest: >- |
34 | 89 | {{ |
35 | 90 | ( |
36 | | - cifmw_basedir | default(ansible_user_dir ~ '/ci-framework-data'), |
37 | | - 'logs/', |
38 | | - now(fmt='%Y-%m-%d_%H-%M') |
| 91 | + cifmw_basedir|default(ansible_user_dir ~ '/ci-framework-data'), |
| 92 | + "artifacts/ansible_facts." + now(fmt='%Y-%m-%d_%H-%M') |
39 | 93 | ) | path_join |
40 | 94 | }} |
41 | | - - name: Generate artifacts |
42 | | - ansible.builtin.import_role: |
43 | | - name: artifacts |
44 | | - |
45 | | - - name: Collect container images used in the environment |
46 | | - ansible.builtin.import_role: |
47 | | - name: env_op_images |
| 95 | + mode: "0777" |
| 96 | + remote_src: true |
48 | 97 |
|
49 | | - - name: Create a versioned log folder |
| 98 | + - name: Clean ansible fact cache |
50 | 99 | ansible.builtin.file: |
51 | | - path: "{{ logfiles_dest_dir }}" |
52 | | - state: directory |
53 | | - mode: "0775" |
54 | | - |
55 | | - - name: Return a list of log files in home directory |
56 | | - ansible.builtin.find: |
57 | | - paths: "{{ ansible_user_dir }}" |
58 | | - patterns: "*.log" |
59 | | - register: _log_files |
60 | | - |
61 | | - - name: Ensure ansible facts cache exists |
62 | | - register: ansible_facts_cache_state |
63 | | - ansible.builtin.stat: |
64 | 100 | path: "{{ ansible_user_dir }}/ansible_facts_cache" |
65 | | - |
66 | | - - name: Copy log files |
67 | | - when: |
68 | | - - _log_files.matched > 0 |
69 | | - block: |
70 | | - - name: Copy logs to proper location |
71 | | - ansible.builtin.copy: |
72 | | - src: "{{ item.path }}" |
73 | | - dest: "{{ [ logfiles_dest_dir , item.path | basename ] | path_join }}" |
74 | | - remote_src: true |
75 | | - mode: "0666" |
76 | | - loop: "{{ _log_files.files }}" |
77 | | - |
78 | | - - name: Remove original log from home directory |
79 | | - ansible.builtin.file: |
80 | | - path: "{{ item.path }}" |
81 | | - state: absent |
82 | | - loop: "{{ _log_files.files }}" |
83 | | - |
84 | | - - name: Copy Ansible facts if exists |
85 | | - when: |
86 | | - - ansible_facts_cache_state.stat.exists is defined |
87 | | - - ansible_facts_cache_state.stat.exists | bool |
88 | | - block: |
89 | | - - name: Copy facts to dated directory |
90 | | - ansible.builtin.copy: |
91 | | - src: "{{ ansible_user_dir }}/ansible_facts_cache" |
92 | | - dest: >- |
93 | | - {{ |
94 | | - ( |
95 | | - cifmw_basedir|default(ansible_user_dir ~ '/ci-framework-data'), |
96 | | - "artifacts/ansible_facts." + now(fmt='%Y-%m-%d_%H-%M') |
97 | | - ) | path_join |
98 | | - }} |
99 | | - mode: "0777" |
100 | | - remote_src: true |
101 | | - |
102 | | - - name: Clean ansible fact cache |
103 | | - ansible.builtin.file: |
104 | | - path: "{{ ansible_user_dir }}/ansible_facts_cache" |
105 | | - state: absent |
| 101 | + state: absent |
0 commit comments