#!/usr/bin/env ansible-playbook --- - name: configure gitlab repository hosts: localhost become: no gather_facts: no vars: namespace: robertdebock-iac vars_files: - defaults/main.yml - vars/main.yml - vars/vault.yml tasks: - name: see if all variables are set assert: that: - namespace is defined - role is defined quiet: yes - name: urlencode path set_fact: encoded_path: "{{ namespace + '%2F' + role }}" - name: place variable block: - name: see 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 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 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: 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: "Monthly test" ref: master cron: "{{ letter_minute_mapping[role[:1]] | default('13') }} {{ letter_hour_mapping[role[:1]] }} {{ letter_day_mapping[role[:1]] }} * *" cron_timezone: Amsterdam # - name: disable runnner # uri: # url: "https://gitlab.com/api/v4/projects/{{ encoded_path }}/runners/{{ gitlab_runner_id }}" # method: DELETE # body_format: json # status_code: # - 204 # - 404 # headers: # PRIVATE-TOKEN: "{{ gitlab_private_token }}" # body: # runner_id: "{{ gitlab_runner_id }}" # - name: enable runnner # uri: # url: "https://gitlab.com/api/v4/projects/{{ encoded_path }}/runners" # method: POST # body_format: json # status_code: # - 201 # - 400 # headers: # PRIVATE-TOKEN: "{{ gitlab_private_token }}" # body: # runner_id: "{{ gitlab_runner_id }}" - name: disable shared runnners uri: url: "https://gitlab.com/api/v4/projects/{{ encoded_path }}" method: PUT body_format: json headers: PRIVATE-TOKEN: "{{ gitlab_private_token }}" body: shared_runners_enabled: false