Sweeper.
This commit is contained in:
parent
fe79fff48f
commit
e2a95426a0
|
|
@ -0,0 +1,54 @@
|
|||
#!/usr/bin/env ansible-playbook
|
||||
---
|
||||
- name: Create a pull mirror gitlab project
|
||||
hosts: localhost
|
||||
become: no
|
||||
gather_facts: no
|
||||
|
||||
vars:
|
||||
github_owner: robertdebock
|
||||
gitlab_namespace: robertdebock-iac
|
||||
|
||||
vars_files:
|
||||
- defaults/main.yml
|
||||
- vars/main.yml
|
||||
- vars/vault.yml
|
||||
|
||||
tasks:
|
||||
- name: see if all variables are set
|
||||
assert:
|
||||
that:
|
||||
- github_owner is defined
|
||||
- role is defined
|
||||
quiet: yes
|
||||
|
||||
- name: Get a detailed list of owned GitLab projects
|
||||
uri:
|
||||
url: "https://gitlab.com/api/v4/projects?owned=true&search={{ role }}"
|
||||
method: GET
|
||||
headers:
|
||||
PRIVATE-TOKEN: "{{ gitlab_private_token }}"
|
||||
return_content: yes
|
||||
register: gitlab_projects
|
||||
|
||||
- name: Pick project_ids from GitLab projects
|
||||
set_fact:
|
||||
gitlab_projects: "{{ gitlab_projects.json | selectattr('name', 'equalto', role) | list }}"
|
||||
|
||||
- name: pick a single project.
|
||||
set_fact:
|
||||
gitlab_project_id: "{{ gitlab_projects[0].id }}"
|
||||
|
||||
- name: Patch existing project to mirror
|
||||
uri:
|
||||
url: "https://gitlab.com/api/v4/projects/{{ gitlab_project_id }}"
|
||||
method: PUT
|
||||
headers:
|
||||
PRIVATE-TOKEN: "{{ gitlab_private_token }}"
|
||||
body_format: json
|
||||
body:
|
||||
visibility: public
|
||||
status_code:
|
||||
- 200
|
||||
register: create_project
|
||||
changed_when: yes
|
||||
|
|
@ -29,45 +29,40 @@
|
|||
headers:
|
||||
Authorization: "Bearer {{ github_token }}"
|
||||
register: github_repo
|
||||
|
||||
# - name: Show shit
|
||||
# debug:
|
||||
# msg: "{{ github_repo.json }}"
|
||||
|
||||
- name: Get GitLab namespace_id
|
||||
|
||||
- name: Get a detailed list of owned GitLab projects
|
||||
uri:
|
||||
url: "https://gitlab.com/api/v4/namespaces"
|
||||
url: "https://gitlab.com/api/v4/projects?owned=true&search={{ role }}"
|
||||
method: GET
|
||||
headers:
|
||||
PRIVATE-TOKEN: "{{ gitlab_private_token }}"
|
||||
return_content: yes
|
||||
register: gitlab_projects
|
||||
|
||||
- name: Pick project_ids from GitLab projects
|
||||
set_fact:
|
||||
gitlab_projects: "{{ gitlab_projects.json | selectattr('name', 'equalto', role) | list }}"
|
||||
|
||||
- name: pick a single project.
|
||||
set_fact:
|
||||
gitlab_project_id: "{{ gitlab_projects[0].id }}"
|
||||
|
||||
- name: Patch existing project to mirror
|
||||
uri:
|
||||
url: "https://gitlab.com/api/v4/projects/{{ gitlab_project_id }}"
|
||||
method: PUT
|
||||
headers:
|
||||
PRIVATE-TOKEN: "{{ gitlab_private_token }}"
|
||||
body_format: json
|
||||
body:
|
||||
search: "{{ gitlab_namespace }}"
|
||||
register: gitlab_namespace
|
||||
|
||||
# - name: Show shit
|
||||
# debug:
|
||||
# msg: "{{ gitlab_namespace.json }}"
|
||||
|
||||
- name: Create a project that pulls from GitHub
|
||||
uri:
|
||||
url: "https://gitlab.com/api/v4/projects"
|
||||
method: POST
|
||||
headers:
|
||||
PRIVATE-TOKEN: "{{ gitlab_private_token }}"
|
||||
body_format: json
|
||||
body:
|
||||
name: "{{ github_repo.json.name }}"
|
||||
description: "{{ github_repo.json.description }}"
|
||||
# TODO: Should the `path` include the namespace:
|
||||
path: "{{ github_repo.json.name }}"
|
||||
namespace_id: 59906445
|
||||
import_url: "{{ github_repo.json.clone_url }}"
|
||||
mirror: true
|
||||
mirror_triggers_builds: true
|
||||
mirror_trigger_builds: true
|
||||
status_code:
|
||||
- 201
|
||||
register: gitlab_project
|
||||
- 200
|
||||
register: create_project
|
||||
changed_when: yes
|
||||
|
||||
# - name: Show shit
|
||||
# debug:
|
||||
# msg: "{{ gitlab_project }}"
|
||||
# - name: Show shit
|
||||
# debug:
|
||||
# msg: "{{ create_project }}"
|
||||
|
|
|
|||
40
gitlab.yml
40
gitlab.yml
|
|
@ -23,7 +23,7 @@
|
|||
|
||||
- name: urlencode path
|
||||
set_fact:
|
||||
encoded_path: "{{ namespace + '%2F' + 'ansible-role-' + role }}"
|
||||
encoded_path: "{{ namespace + '%2F' + role }}"
|
||||
|
||||
- name: place variable
|
||||
block:
|
||||
|
|
@ -56,25 +56,25 @@
|
|||
protects: true
|
||||
masked: true
|
||||
|
||||
- name: list pipeline schedules
|
||||
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 pipeline schedules
|
||||
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: list pipeline schedules
|
||||
# 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 pipeline schedules
|
||||
# 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:
|
||||
|
|
|
|||
Loading…
Reference in New Issue