-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgitlab-v2.yml
executable file
·101 lines (91 loc) · 2.82 KB
/
gitlab-v2.yml
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/usr/bin/env ansible-playbook
---
- name: configure gitlab repository
hosts: localhost
become: false
gather_facts: true
vars:
namespace: buluma
vars_files:
- vars/main.yml
- vars/vault.yml
tasks:
- name: set role_path and role
set_fact:
role_path: "{{ lookup('env', 'PWD') }}"
role: "{{ lookup('env', 'PWD') | basename | regex_replace('ansible-role-') }}"
# - name: verify role name
# - debug:
# msg: "{{ role }}"
- name: see if all variables are set
assert:
that:
- namespace is defined
- role is defined
quiet: true
- name: urlencode path
set_fact:
encoded_path: "{{ namespace + '%2Fansible-role-' + role }}"
- name: place variable
block:
- name: check if the variable is set already
uri:
url: "https://gitlab.com/api/v4/projects/{{ encoded_path }}/variables"
method: GET
body_format: json
headers:
PRIVATE-TOKEN: "{{ gitlab_private_token }}"
body:
key: "GALAXY_API_KEY"
register: check_variable
failed_when:
check_variable.json | length <= 0
ignore_errors: true
rescue:
- name: place variable
uri:
url: "https://gitlab.com/api/v4/projects/{{ encoded_path }}/variables"
method: POST
body_format: json
status_code:
- 201
headers:
PRIVATE-TOKEN: "{{ gitlab_private_token }}"
body:
key: "GALAXY_API_KEY"
value: "{{ galaxy_api_key }}"
variable_type: env_var
protects: true
masked: true
- name: list pipelines
uri:
url: "https://gitlab.com/api/v4/projects/{{ encoded_path }}/pipeline_schedules"
method: GET
headers:
PRIVATE-TOKEN: "{{ gitlab_private_token }}"
register: gitlab_schedules
- name: delete all pipelines
uri:
url: "https://gitlab.com/api/v4/projects/{{ encoded_path }}/pipeline_schedules/{{ item.id }}"
method: DELETE
headers:
PRIVATE-TOKEN: "{{ gitlab_private_token }}"
status_code:
- 204
loop: "{{ gitlab_schedules.json }}"
loop_control:
label: "{{ item.id }}"
- name: create a new pipeline schedule
uri:
url: "https://gitlab.com/api/v4/projects/{{ encoded_path }}/pipeline_schedules"
method: POST
body_format: json
status_code:
- 201
headers:
PRIVATE-TOKEN: "{{ gitlab_private_token }}"
body:
description: "Daily test"
ref: master
cron: "{{ letter_minute_mapping[role[1]] | default('0') }} */8 * * *"
cron_timezone: Africa/Nairobi