feat(ansible): mirror gitlab repositories fron gitea

This commit is contained in:
Michele Cereda
2025-01-12 22:35:06 +01:00
parent d3cd3c432e
commit 70f6fadce1
4 changed files with 81 additions and 5 deletions

View File

@@ -22,6 +22,14 @@ ansible-playbook 'gitlab.yml' --list-tasks
ansible-playbook 'gitlab.yml' --list-tasks --tags 'configuration,packages'
ansible-playbook 'gitlab.yml' --list-tasks --skip-tags 'system,user'
# List installed collections
ansible-galaxy collection list
# Install collections
ansible-galaxy collection install 'community.general'
ansible-galaxy collection install 'amazon.aws:9.1.0' '/path/to/collection' 'git+file:///path/to/collection.git'
ansible-galaxy collection install -r 'requirements.yml'
# Create new roles
ansible-galaxy init 'gitlab'
ansible-galaxy role init 'my_role'
@@ -106,15 +114,15 @@ diff 'some_role/files/ssh.key.plain' <(ansible-vault view --vault-password-file
ansible-doc -t 'lookup' -l
ansible-doc -t 'strategy' -l
# List installed collections
ansible-galaxy collection list
# Show plugin-specific docs and examples
ansible-doc -t 'lookup' 'fileglob'
ansible-doc -t 'strategy' 'linear'
# Run commands within Execution Environments
ansible-navigator exec
venv/bin/ansible-navigator --mode='stdout' --container-options='--platform=linux/amd64' \
--execution-environment-image='012345678901.dkr.ecr.eu-west-1.amazonaws.com/infra/ansible-ee' \
exec -- ansible-galaxy collection list
AWS_PROFILE='AnsibleTaskExecutor' venv/bin/ansible-navigator \
--execution-environment-image='012345678901.dkr.ecr.eu-west-1.amazonaws.com/infra/ansible-ee' \
--execution-environment-volume-mounts="$HOME/.aws:/runner/.aws:ro" \

View File

@@ -848,6 +848,10 @@
# The datetime format defaults to '%Y-%m-%d %H:%M:%S'.
tags: datetime
block:
- name: Add or remove time
ansible.builtin.set_fact:
one_year_from_now: "{{ '%Y-%m-%dT%H:%M:%S' | strftime( (ansible_date_time.epoch_int) + (60*60*24*365) ) }}"
one_year_from_now_date_only: "{{ '%Y-%m-%d' | strftime( now(fmt='%s')|int + (60*60*24*365) ) }}"
- name: Compare date and times
ansible.builtin.set_fact:
total_seconds_between_dates: >-
@@ -1239,8 +1243,46 @@
all: true
register: awx_export_output
- name: Gitea-specific operations
tags:
- gitea
- never
hosts: localhost
connection: local
gather_facts: false
check_mode: true
tasks:
- name: Create a GitLab mirror repository in Gitea
tags: create_gitea_mirror_gitlab
ansible.builtin.uri:
url: https://gitea.example.org/api/v1/repos/migrate
method: POST
headers:
Authorization: token abcdef0123456789abcdef0123456789abcdef01
body_format: json
body:
auth_username: ro-access
auth_token: glpat-projAccesToken012345
clone_addr: https://gitlab.example.org/jimmy/secret-project
issues: false
labels: false
lfs: false
milestones: false
mirror: true
mirror_interval: 8h0m0s
private: true
pull_requests: false
releases: false
repo_name: secret-project
repo_owner: jimmy
service: gitlab
wiki: false
status_code: 201
- name: GitLab-specific operations
tags: never
tags:
- gitlab
- never
hosts: localhost
connection: local
gather_facts: false
@@ -1253,6 +1295,24 @@
chdir: /root
cmd: gitlab-runner fleeting install
creates: /root/.config/fleeting/plugins
- name: Create a Project Access Token for Gitea in GitLab
tags: create_gitlab_project_access_token
block:
- name: Create the access token
community.general.gitlab_project_access_token:
api_url: https://gitlab.example.org
api_token: glpat-m-PLACEHOLDER0123456
project: jimmy/secret-project
name: ro-access
expires_at: "{{ '%Y-%m-%d' | strftime( now(fmt='%s')|int + (60*60*24*365) ) }}" # 1y from now
access_level: guest
scopes:
- read_api
- read_repository
register: gitlab_project_access_token_creation
- name: Save the access token for later use
ansible.builtin.set_fact:
gitlab_project_access_token: "{{ gitlab_project_access_token_creation.access_token.token }}"
- name: Let's Encrypt-specific operations
tags: never

View File

@@ -10,3 +10,9 @@ docker exec -ti 'gitea-server-1' sh
# Generate self-signed certificates
gitea cert --host 'gitea.lan'
# List organizations
curl -fsSL -H 'Authorization: token abcdef0123456789abcdef0123456789abcdef01' 'https://gitea.example.org/api/v1/orgs'
# Get repository information
curl -fsSL -H 'Authorization: token a…1' 'https://gitea.example.org/api/v1/repos/john/templates'

View File

@@ -81,3 +81,5 @@ pg_restore -h 'host.fqdn' -U 'master' -d 'sales' -Oxj '8' 'sales.dump'
# Initialize a test DB
pgbench -i 'test-db'
pgbench -i 'test-db' -h 'hostname' -p '5555' -U 'user'
pg_isready -U 'denis' -d 'sales'