mirror of
https://github.com/ublue-os/forge.git
synced 2025-07-04 16:55:45 +03:00
feat: automatically setup forge (#10)
This commit is contained in:
parent
c694947618
commit
bbe78ee922
28 changed files with 1472 additions and 0 deletions
11
setup/ansible/roles/semaphore/tasks/authentication.yml
Normal file
11
setup/ansible/roles/semaphore/tasks/authentication.yml
Normal file
|
@ -0,0 +1,11 @@
|
|||
---
|
||||
- name: Get API token
|
||||
ansible.builtin.uri:
|
||||
url: "http://{{ ansible_host }}:3000/api/auth/login"
|
||||
method: POST
|
||||
body:
|
||||
auth: "{{ semaphore_admin_user }}"
|
||||
password: "{{ semaphore_admin_password }}"
|
||||
body_format: json
|
||||
status_code: 204
|
||||
register: semaphore_login
|
45
setup/ansible/roles/semaphore/tasks/environments.yml
Normal file
45
setup/ansible/roles/semaphore/tasks/environments.yml
Normal file
|
@ -0,0 +1,45 @@
|
|||
---
|
||||
- name: Check for existing environments
|
||||
changed_when: false
|
||||
check_mode: false
|
||||
ansible.builtin.uri:
|
||||
url: "http://{{ ansible_host }}:3000/api/project/{{ semaphore_project_id }}/environment"
|
||||
method: GET
|
||||
headers:
|
||||
Cookie: "{{ semaphore_login.cookies_string }}"
|
||||
status_code: 200
|
||||
timeout: 5
|
||||
register: semaphore_environments
|
||||
|
||||
- name: Create default environment
|
||||
changed_when: "semaphore_environment_created.status == 204"
|
||||
ansible.builtin.uri:
|
||||
url: "http://{{ ansible_host }}:3000/api/project/{{ semaphore_project_id }}/environment"
|
||||
method: POST
|
||||
headers:
|
||||
Cookie: "{{ semaphore_login.cookies_string }}"
|
||||
# Body in YAML format is not working
|
||||
body: "{{ lookup('ansible.builtin.template', 'environment.yml.j2') | from_yaml | to_json }}"
|
||||
body_format: json
|
||||
status_code: 204
|
||||
timeout: 5
|
||||
register: semaphore_environment_created
|
||||
when: semaphore_environments.json | selectattr('name', 'equalto', 'default') | length == 0
|
||||
|
||||
- name: Check for environments (after creation)
|
||||
changed_when: false
|
||||
check_mode: false
|
||||
ansible.builtin.uri:
|
||||
url: "http://{{ ansible_host }}:3000/api/project/{{ semaphore_project_id }}/environment"
|
||||
method: GET
|
||||
headers:
|
||||
Cookie: "{{ semaphore_login.cookies_string }}"
|
||||
status_code: 200
|
||||
timeout: 5
|
||||
register: semaphore_environments
|
||||
|
||||
- name: Parse semaphore_environment_id
|
||||
ansible.builtin.set_fact:
|
||||
semaphore_environment_id: "{{ semaphore_environments.json \
|
||||
| selectattr('name', 'equalto', 'default') \
|
||||
| map(attribute='id') | first }}"
|
35
setup/ansible/roles/semaphore/tasks/inventories.yml
Normal file
35
setup/ansible/roles/semaphore/tasks/inventories.yml
Normal file
|
@ -0,0 +1,35 @@
|
|||
---
|
||||
- name: Check for existing inventories
|
||||
changed_when: false
|
||||
ansible.builtin.uri:
|
||||
url: "http://{{ ansible_host }}:3000/api/project/{{ semaphore_project_id }}/inventory"
|
||||
method: GET
|
||||
headers:
|
||||
Cookie: "{{ semaphore_login.cookies_string }}"
|
||||
status_code: 200
|
||||
timeout: 5
|
||||
register: semaphore_inventories
|
||||
|
||||
- name: Create Inventory
|
||||
changed_when: "semaphore_inventory_created.status == 201"
|
||||
ansible.builtin.uri:
|
||||
url: "http://{{ ansible_host }}:3000/api/project/{{ semaphore_project_id }}/inventory"
|
||||
method: POST
|
||||
headers:
|
||||
Cookie: "{{ semaphore_login.cookies_string }}"
|
||||
body: "{{ lookup('ansible.builtin.template', 'inventory.yml.j2') | from_yaml | to_json }}"
|
||||
body_format: json
|
||||
status_code: 201
|
||||
timeout: 5
|
||||
register: semaphore_inventory_created
|
||||
when: semaphore_inventories.json | selectattr('name', 'equalto', semaphore_project_name) | length == 0
|
||||
|
||||
- name: Parse semaphore_inventory_id (existing)
|
||||
ansible.builtin.set_fact:
|
||||
semaphore_inventory_id: "{{ semaphore_inventories.json | selectattr('name', 'equalto', semaphore_project_name) | map(attribute='id') | first }}"
|
||||
when: semaphore_inventories.json | selectattr('name', 'equalto', semaphore_project_name) | length > 0
|
||||
|
||||
- name: Parse semaphore_inventory_id (created)
|
||||
ansible.builtin.set_fact:
|
||||
semaphore_inventory_id: "{{ semaphore_inventory_created.json.id }}"
|
||||
when: semaphore_inventories.json | selectattr('name', 'equalto', semaphore_project_name) | length == 0
|
40
setup/ansible/roles/semaphore/tasks/keys.yml
Normal file
40
setup/ansible/roles/semaphore/tasks/keys.yml
Normal file
|
@ -0,0 +1,40 @@
|
|||
---
|
||||
- name: Check for existing keystore
|
||||
changed_when: false
|
||||
ansible.builtin.uri:
|
||||
url: "http://{{ ansible_host }}:3000/api/project/{{ semaphore_project_id }}/keys"
|
||||
method: GET
|
||||
headers:
|
||||
Cookie: "{{ semaphore_login.cookies_string }}"
|
||||
status_code: 200
|
||||
timeout: 5
|
||||
register: semaphore_keystores
|
||||
|
||||
- name: Create key of type None
|
||||
changed_when: "semaphore_key_ansible_created.status == 204"
|
||||
ansible.builtin.uri:
|
||||
url: "http://{{ ansible_host }}:3000/api/project/{{ semaphore_project_id }}/keys"
|
||||
method: POST
|
||||
headers:
|
||||
Cookie: "{{ semaphore_login.cookies_string }}"
|
||||
body: "{{ lookup('ansible.builtin.template', 'key.yml.j2') | from_yaml | to_json }}"
|
||||
body_format: json
|
||||
status_code: 204
|
||||
timeout: 5
|
||||
register: semaphore_key_ansible_created
|
||||
when: semaphore_keystores.json | selectattr('name', 'equalto', 'None') | length == 0
|
||||
|
||||
- name: Get key id
|
||||
changed_when: false
|
||||
ansible.builtin.uri:
|
||||
url: "http://{{ ansible_host }}:3000/api/project/{{ semaphore_project_id }}/keys"
|
||||
method: GET
|
||||
headers:
|
||||
Cookie: "{{ semaphore_login.cookies_string }}"
|
||||
status_code: 200
|
||||
timeout: 5
|
||||
register: semaphore_keystores
|
||||
|
||||
- name: Parse semaphore_ansible_none_key_id
|
||||
ansible.builtin.set_fact:
|
||||
semaphore_ansible_none_key_id: "{{ semaphore_keystores.json | selectattr('name', 'equalto', 'None') | map(attribute='id') | first }}"
|
28
setup/ansible/roles/semaphore/tasks/main.yml
Normal file
28
setup/ansible/roles/semaphore/tasks/main.yml
Normal file
|
@ -0,0 +1,28 @@
|
|||
---
|
||||
- name: API authentication
|
||||
ansible.builtin.include_tasks:
|
||||
file: authentication.yml
|
||||
|
||||
- name: Add projects
|
||||
ansible.builtin.include_tasks:
|
||||
file: projects.yml
|
||||
|
||||
- name: Add keys
|
||||
ansible.builtin.include_tasks:
|
||||
file: keys.yml
|
||||
|
||||
- name: Add repositories
|
||||
ansible.builtin.include_tasks:
|
||||
file: repositories.yml
|
||||
|
||||
- name: Add environment
|
||||
ansible.builtin.include_tasks:
|
||||
file: environments.yml
|
||||
|
||||
- name: Add inventory
|
||||
ansible.builtin.include_tasks:
|
||||
file: inventories.yml
|
||||
|
||||
- name: Add templates
|
||||
ansible.builtin.include_tasks:
|
||||
file: templates.yml
|
36
setup/ansible/roles/semaphore/tasks/projects.yml
Normal file
36
setup/ansible/roles/semaphore/tasks/projects.yml
Normal file
|
@ -0,0 +1,36 @@
|
|||
---
|
||||
- name: Check for existing projects
|
||||
changed_when: false
|
||||
ansible.builtin.uri:
|
||||
url: "http://{{ ansible_host }}:3000/api/projects"
|
||||
method: GET
|
||||
headers:
|
||||
Cookie: "{{ semaphore_login.cookies_string }}"
|
||||
status_code: 200
|
||||
timeout: 5
|
||||
register: semaphore_projects
|
||||
|
||||
- name: Create project
|
||||
changed_when: "semaphore_project_created.status == 201"
|
||||
ansible.builtin.uri:
|
||||
url: "http://{{ ansible_host }}:3000/api/projects"
|
||||
method: POST
|
||||
headers:
|
||||
Cookie: "{{ semaphore_login.cookies_string }}"
|
||||
body:
|
||||
name: "{{ semaphore_project_name }}"
|
||||
body_format: json
|
||||
status_code: 201
|
||||
timeout: 5
|
||||
register: semaphore_project_created
|
||||
when: semaphore_project_name not in semaphore_projects.json | map(attribute='name')
|
||||
|
||||
- name: Parse semaphore_project_id (existing)
|
||||
ansible.builtin.set_fact:
|
||||
semaphore_project_id: "{{ semaphore_projects.json | selectattr('name', 'equalto', semaphore_project_name) | map(attribute='id') | first }}"
|
||||
when: semaphore_project_name in semaphore_projects.json | map(attribute='name')
|
||||
|
||||
- name: Parse semaphore_project_id (created)
|
||||
ansible.builtin.set_fact:
|
||||
semaphore_project_id: "{{ semaphore_project_created.json.id }}"
|
||||
when: semaphore_project_name not in semaphore_projects.json | map(attribute='name')
|
42
setup/ansible/roles/semaphore/tasks/repositories.yml
Normal file
42
setup/ansible/roles/semaphore/tasks/repositories.yml
Normal file
|
@ -0,0 +1,42 @@
|
|||
---
|
||||
- name: Check for existing repositories
|
||||
changed_when: false
|
||||
ansible.builtin.uri:
|
||||
url: "http://{{ ansible_host }}:3000/api/project/{{ semaphore_project_id }}/repositories"
|
||||
method: GET
|
||||
headers:
|
||||
Cookie: "{{ semaphore_login.cookies_string }}"
|
||||
status_code: 200
|
||||
timeout: 5
|
||||
register: semaphore_repositories
|
||||
|
||||
- name: Create Repository
|
||||
changed_when: "semaphore_repository_created.status == 204"
|
||||
ansible.builtin.uri:
|
||||
url: "http://{{ ansible_host }}:3000/api/project/{{ semaphore_project_id }}/repositories"
|
||||
method: POST
|
||||
headers:
|
||||
Cookie: "{{ semaphore_login.cookies_string }}"
|
||||
body: "{{ lookup('ansible.builtin.template', 'repository.yml.j2') | from_yaml | to_json }}"
|
||||
body_format: json
|
||||
status_code: 204
|
||||
timeout: 5
|
||||
register: semaphore_repository_created
|
||||
when: semaphore_repositories.json | selectattr('name', 'equalto', semaphore_repository_name) | length == 0
|
||||
|
||||
- name: Get repository id
|
||||
changed_when: false
|
||||
ansible.builtin.uri:
|
||||
url: "http://{{ ansible_host }}:3000/api/project/{{ semaphore_project_id }}/repositories"
|
||||
method: GET
|
||||
headers:
|
||||
Cookie: "{{ semaphore_login.cookies_string }}"
|
||||
status_code: 200
|
||||
timeout: 5
|
||||
register: semaphore_repositories
|
||||
|
||||
- name: Parse semaphore_repository_id
|
||||
ansible.builtin.set_fact:
|
||||
semaphore_repository_id: "{{ semaphore_repositories.json \
|
||||
| selectattr('name', 'equalto', semaphore_repository_name) \
|
||||
| map(attribute='id') | first }}"
|
29
setup/ansible/roles/semaphore/tasks/templates.yml
Normal file
29
setup/ansible/roles/semaphore/tasks/templates.yml
Normal file
|
@ -0,0 +1,29 @@
|
|||
---
|
||||
- name: Check for existing templates
|
||||
changed_when: false
|
||||
ansible.builtin.uri:
|
||||
url: "http://{{ ansible_host }}:3000/api/project/{{ semaphore_project_id }}/templates"
|
||||
method: GET
|
||||
headers:
|
||||
Cookie: "{{ semaphore_login.cookies_string }}"
|
||||
status_code: 200
|
||||
timeout: 5
|
||||
register: semaphore_templates
|
||||
|
||||
- name: Create templates
|
||||
changed_when: "semaphore_template_created.status == 201"
|
||||
ansible.builtin.uri:
|
||||
url: "http://{{ ansible_host }}:3000/api/project/{{ semaphore_project_id }}/templates"
|
||||
method: POST
|
||||
headers:
|
||||
Content-Type: application/json
|
||||
Cookie: "{{ semaphore_login.cookies_string }}"
|
||||
body: "{{ lookup('ansible.builtin.template', 'template.yml.j2') | from_yaml | to_json }} }}"
|
||||
body_format: json
|
||||
status_code: 201
|
||||
timeout: 5
|
||||
register: semaphore_template_created
|
||||
when: semaphore_templates.json | selectattr('name', 'equalto', item.name) | length == 0
|
||||
loop_control:
|
||||
label: "Task {{ item.name }}"
|
||||
loop: "{{ semaphore_tasks }}"
|
Loading…
Add table
Add a link
Reference in a new issue