-
Notifications
You must be signed in to change notification settings - Fork 1
/
bitbucket-fork.yml
59 lines (49 loc) · 1.61 KB
/
bitbucket-fork.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
---
# -----------------
# qd: fork bitbucket project and clone locally.
- hosts: localhost
gather_facts: false
become: false
connection: local
vars:
bbsite: "bb.example.redhat.com"
bitbucket_group: default
pb_user: "{{ lookup('pipe','whoami') }}"
pb_home: "{{ lookup('env','HOME') }}"
dest: "{{ lookup('env',"GIT_HOME") | default('/home/') }}/{{ pb_user }}/GIT/roles/{{ repos }}"
bitbucket_url: "https://{{ bbsite }}/git/rest/api/latest"
bb_url: "{{ bitbucket_url }}/projects/{{ bitbucket_group }}/repos/{{ repos }}"
tasks:
- assert:
that:
- repos is defined
- repos | length > 2
fail_msg: "ooops, no repos"
- name: "Include vars for access"
no_log: true
include_vars:
file: "{{ '{}/.ansible_vars_{}.yml'.format( pb_home, pb_user ) }}"
when: bitbucket_password is undefined
- name: 'Fork a respository'
uri:
url: "{{ bb_url }}"
method: POST
status_code: [200,201,409]
user: "{{ bitbucket_user }}"
password: "{{ bitbucket_password }}"
force_basic_auth: true
body_format: json
body:
name: "{{ target_repos if target_repos is defined else repos }}"
scm: "git"
is_private: false
register: fork_result
- name: 'debug'
debug:
var: fork_result.json.errors
when: fork_result.json.errors is defined
- name: 'GIT Clone'
git:
repo: "https://{{ bitbucket_user }}:{{ bitbucket_password }}@{{ bbsite }}/git/scm/~{{ bitbucket_user }}/{{ repos }}.git"
dest: "{{ dest }}"