63 lines
1.7 KiB
YAML
Executable File
63 lines
1.7 KiB
YAML
Executable File
#!/usr/bin/env ansible-playbook
|
|
---
|
|
- name: Kick off a pipeline for a GitLab project
|
|
hosts: localhost
|
|
become: no
|
|
gather_facts: no
|
|
|
|
vars:
|
|
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:
|
|
- gitlab_namespace is defined
|
|
- role is defined
|
|
quiet: yes
|
|
|
|
- name: Get GitLab project number
|
|
uri:
|
|
url: https://gitlab.com/api/v4/projects/{{ gitlab_namespace }}%2F{{ role }}
|
|
headers:
|
|
PRIVATE-TOKEN: "{{ gitlab_private_token }}"
|
|
register: gitlab_project_details
|
|
|
|
- name: Create pipeline trigger
|
|
uri:
|
|
url: "https://gitlab.com/api/v4/projects/{{ gitlab_project_details.json.id }}/triggers"
|
|
method: POST
|
|
headers:
|
|
PRIVATE-TOKEN: "{{ gitlab_private_token }}"
|
|
body_format: form-urlencoded
|
|
body:
|
|
description: "Ansible"
|
|
status_code:
|
|
- 201
|
|
register: pipeline_trigger
|
|
|
|
- name: Trigger pipeline
|
|
uri:
|
|
url: "https://gitlab.com/api/v4/projects/{{ gitlab_project_details.json.id }}/trigger/pipeline"
|
|
method: POST
|
|
body_format: form-urlencoded
|
|
body:
|
|
token: "{{ pipeline_trigger.json.token }}"
|
|
ref: master
|
|
status_code:
|
|
- 201
|
|
|
|
- name: Delete pipeline trigger
|
|
uri:
|
|
url: "https://gitlab.com/api/v4/projects/{{ gitlab_project_details.json.id }}/triggers/{{ pipeline_trigger.json.id }}"
|
|
method: DELETE
|
|
headers:
|
|
PRIVATE-TOKEN: "{{ gitlab_private_token }}"
|
|
status_code:
|
|
- 204
|