ansible-generator/github.yml

97 lines
2.5 KiB
YAML
Executable File

#!/usr/bin/env ansible-playbook
---
- name: github
hosts: localhost
become: no
gather_facts: no
vars_files:
# - defaults/main.yml
- vars/main.yml
- vars/vault.yml
pre_tasks:
- name: see if all variables are set
assert:
that:
- github_namespace is defined
- repo is defined
- github_token is defined
quiet: yes
tasks:
- name: list webhooks
uri:
url: "https://api.github.com/repos/{{ github_namespace }}/{{ repo }}/hooks"
headers:
Accept: "application/vnd.github+json"
Authorization: "Bearer {{ github_token }}"
register: github_webhooks
- name: show delivery url for gitlab webhook
set_fact:
deliveries_url: "{{ item.deliveries_url }}"
loop: "{{ github_webhooks.json }}"
loop_control:
label: "{{ item.id }}"
when:
- '"gitlab.com" in item.config.url'
- name: list delivery
uri:
url: "{{ deliveries_url }}"
headers:
Accept: "application/vnd.github+json"
Authorization: "Bearer {{ github_token }}"
register: deliveries
- name: add repo to github-okay.txt
lineinfile:
line: "{{ repo }}"
path: github-okay.txt
create: yes
loop: "{{ deliveries.json }}"
loop_control:
label: "{{ repo }} - {{ item.id }} - {{ item.status_code }}"
when:
- item.event == "push"
- item.status_code == 200
- name: remove repo from github-okay.txt
lineinfile:
line: "{{ repo }}"
path: github-okay.txt
state: absent
create: yes
loop: "{{ deliveries.json }}"
loop_control:
label: "{{ repo }} - {{ item.id }} - {{ item.status_code }}"
when:
- item.event == "push"
- item.status_code != 200
- name: add repo to github-fail.txt
lineinfile:
line: "{{ repo }}"
path: github-fail.txt
create: yes
loop: "{{ deliveries.json }}"
loop_control:
label: "{{ repo }} - {{ item.id }} - {{ item.status_code }}"
when:
- item.event == "push"
- item.status_code != 200
- name: remove repo from github-fail.txt
lineinfile:
line: "{{ repo }}"
path: github-fail.txt
state: absent
create: yes
loop: "{{ deliveries.json }}"
loop_control:
label: "{{ repo }} - {{ item.id }} - {{ item.status_code }}"
when:
- item.event == "push"
- item.status_code == 200