diff --git a/snippets/ansible/commands.sh b/snippets/ansible/commands.sh index 94c942d..4e0c3de 100644 --- a/snippets/ansible/commands.sh +++ b/snippets/ansible/commands.sh @@ -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" \ diff --git a/snippets/ansible/tasks.yml b/snippets/ansible/tasks.yml index 50f5314..7455c25 100644 --- a/snippets/ansible/tasks.yml +++ b/snippets/ansible/tasks.yml @@ -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: >- @@ -867,7 +871,7 @@ date1_short: # Shorten to microseconds # Works for any timestamp that has higher than microsecond precision by cutting off anything more precise than that - '{{ date1|regex_replace("([^.]+)(\.\d{6})(\d*)(.+)", "\1\2\4") }}' + '{{ date1 | regex_replace("([^.]+)(\.\d{6})(\d*)(.+)", "\1\2\4") }}' iso8601format: '%Y-%m-%dT%H:%M:%S.%fZ' ansible.builtin.set_fact: date_diff_isoed: '{{ (date1_short|to_datetime(iso8601format) - date2|to_datetime(iso8601format)).total_seconds() }}' @@ -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 diff --git a/snippets/gitea.sh b/snippets/gitea.sh index 2efb994..3e36b68 100644 --- a/snippets/gitea.sh +++ b/snippets/gitea.sh @@ -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' diff --git a/snippets/postgres/commands.sh b/snippets/postgres/commands.sh index 9c887d9..e885b7b 100644 --- a/snippets/postgres/commands.sh +++ b/snippets/postgres/commands.sh @@ -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'