From 182b8189dcf80911aed27e9065c7386f5b3b5ef1 Mon Sep 17 00:00:00 2001 From: Marius Ghita Date: Sat, 25 Jan 2025 17:28:57 +0200 Subject: [PATCH 1/6] refactor: playbook-cwd.yaml -> apply.yaml #0000 Make it more obvious which playbook one should use for the general case. --- .github/workflows/update-readme.yaml | 2 +- Dockerfile | 2 +- README.md | 4 ++-- playbook-cwd.yaml => apply.yaml | 0 docs/partials/readme.installation.md | 4 ++-- 5 files changed, 6 insertions(+), 6 deletions(-) rename playbook-cwd.yaml => apply.yaml (100%) diff --git a/.github/workflows/update-readme.yaml b/.github/workflows/update-readme.yaml index 562366f..26b6252 100644 --- a/.github/workflows/update-readme.yaml +++ b/.github/workflows/update-readme.yaml @@ -24,7 +24,7 @@ jobs: run: python3 library/schema_to_docs_partial.py - name: run ansible playbook - run: ansible-playbook playbook-cwd.yaml + run: ansible-playbook apply.yaml env: ANSIBLE_DISPLAY_OK_HOSTS: 0 ANSIBLE_DISPLAY_SKIPPED_HOSTS: 0 diff --git a/Dockerfile b/Dockerfile index e80ec5d..c7e41ba 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,4 +17,4 @@ ENV ANSIBLE_DISPLAY_OK_HOSTS=0 ENV ANSIBLE_DISPLAY_SKIPPED_HOSTS=0 # Set the default command to run when the container starts -CMD ansible-playbook -ilocalhost, /opt/repo-ansible/playbook-cwd.yaml +CMD ansible-playbook -ilocalhost, /opt/repo-ansible/apply.yaml diff --git a/README.md b/README.md index 0b476af..88852b1 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ docker pull ghcr.io/linkorb/repo-ansible:latest docker run --rm -v "$PWD":/app ghcr.io/linkorb/repo-ansible:latest ``` -> This command will execute the repo-ansible playbook-cwd.yaml in your current directory and report on the tasks +> This command will execute the repo-ansible apply.yaml in your current directory and report on the tasks > that reported changes throughout the execution. @@ -58,7 +58,7 @@ $ pip3 install jsonschema ```shell -/your-repository $ ansible-playbook /tmp/repo-ansible/playbook-cwd.yaml +/your-repository $ ansible-playbook /tmp/repo-ansible/apply.yaml PLAY [localhost] ************************************************************************** diff --git a/playbook-cwd.yaml b/apply.yaml similarity index 100% rename from playbook-cwd.yaml rename to apply.yaml diff --git a/docs/partials/readme.installation.md b/docs/partials/readme.installation.md index faca1ce..8be828b 100644 --- a/docs/partials/readme.installation.md +++ b/docs/partials/readme.installation.md @@ -13,7 +13,7 @@ docker pull ghcr.io/linkorb/repo-ansible:latest docker run --rm -v "$PWD":/app ghcr.io/linkorb/repo-ansible:latest ``` -> This command will execute the repo-ansible playbook-cwd.yaml in your current directory and report on the tasks +> This command will execute the repo-ansible apply.yaml in your current directory and report on the tasks > that reported changes throughout the execution. @@ -40,7 +40,7 @@ $ pip3 install jsonschema ```shell -/your-repository $ ansible-playbook /tmp/repo-ansible/playbook-cwd.yaml +/your-repository $ ansible-playbook /tmp/repo-ansible/apply.yaml PLAY [localhost] ************************************************************************** From c59e2c76437173851a97b87c0e135e13fcb49286 Mon Sep 17 00:00:00 2001 From: Marius Ghita Date: Sat, 25 Jan 2025 17:31:31 +0200 Subject: [PATCH 2/6] fix(ci): unecessary xargs call #0000 --- .github/workflows/update-readme.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/update-readme.yaml b/.github/workflows/update-readme.yaml index 26b6252..e803ea4 100644 --- a/.github/workflows/update-readme.yaml +++ b/.github/workflows/update-readme.yaml @@ -18,7 +18,7 @@ jobs: # XXX ansible installed within GitHub Runner via pipx, which doesn't support direct installation from a file # like pip does. See https://github.com/pypa/pipx/issues/934 - name: install repo-ansible dependencies - run: xargs pipx inject ansible-core jsonschema + run: pipx inject ansible-core jsonschema - name: generate schema README table (markdown partial) run: python3 library/schema_to_docs_partial.py From 5880923a5a5aa84d84c06378af2602a785096814 Mon Sep 17 00:00:00 2001 From: Marius Ghita Date: Sat, 25 Jan 2025 17:33:55 +0200 Subject: [PATCH 3/6] chore: consistent naming pattern of workflow #0000 --- .github/workflows/{update-readme.yaml => auto-update-readme.yaml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/workflows/{update-readme.yaml => auto-update-readme.yaml} (100%) diff --git a/.github/workflows/update-readme.yaml b/.github/workflows/auto-update-readme.yaml similarity index 100% rename from .github/workflows/update-readme.yaml rename to .github/workflows/auto-update-readme.yaml From 522b7456d32cb8ab058b12bd4270ae99dbe91572 Mon Sep 17 00:00:00 2001 From: Marius Ghita Date: Sat, 25 Jan 2025 17:48:47 +0200 Subject: [PATCH 4/6] refactor: bulk playbooks in single file #0000 --- playbook-all.yaml => bulk-apply.yaml | 1 - docs/BulkOperations.md | 2 +- playbook-checkout.yaml | 12 ------------ playbook-pull-request.yaml | 11 ----------- playbook-push.yaml | 11 ----------- 5 files changed, 1 insertion(+), 36 deletions(-) rename playbook-all.yaml => bulk-apply.yaml (98%) delete mode 100644 playbook-checkout.yaml delete mode 100644 playbook-pull-request.yaml delete mode 100644 playbook-push.yaml diff --git a/playbook-all.yaml b/bulk-apply.yaml similarity index 98% rename from playbook-all.yaml rename to bulk-apply.yaml index 22a52c6..72d55fe 100644 --- a/playbook-all.yaml +++ b/bulk-apply.yaml @@ -1,6 +1,5 @@ - hosts: all connection: local - strategy: free vars: base_path: "{{ lookup('env', 'REPO_ANSIBLE_BASE_PATH') or (playbook_dir + '/workspace') }}" repo_path: "{{ base_path }}/{{ inventory_hostname }}" diff --git a/docs/BulkOperations.md b/docs/BulkOperations.md index 044a917..2e1d6bb 100644 --- a/docs/BulkOperations.md +++ b/docs/BulkOperations.md @@ -1,5 +1,5 @@ -The repository contains playbooks that can simultaneously operate across multiple repositories (e.g., `playbook-all.yaml`). +The repository contains playbooks that can simultaneously operate across multiple repositories (e.g., `bulk-apply.yaml`). These bulk operations require an inventory file that makes up the "hosts" upon which it should operate. In this context, the hosts are the names of the repositories, which should be in an automatic fashion: checked out, modified per diff --git a/playbook-checkout.yaml b/playbook-checkout.yaml deleted file mode 100644 index 819d39b..0000000 --- a/playbook-checkout.yaml +++ /dev/null @@ -1,12 +0,0 @@ -- hosts: all - connection: local - strategy: free - gather_facts: false - vars: - base_path: "{{ lookup('env', 'REPO_ANSIBLE_BASE_PATH') or (playbook_dir + '/workspace') }}" - repo_path: "{{ base_path }}/{{ inventory_hostname }}" - tasks: - - import_tasks: tasks/checkout.yaml - vars: - repository: "{{ inventory_hostname }}" - destination: "{{ repo_path }}" diff --git a/playbook-pull-request.yaml b/playbook-pull-request.yaml deleted file mode 100644 index e55cdc0..0000000 --- a/playbook-pull-request.yaml +++ /dev/null @@ -1,11 +0,0 @@ -- hosts: all - connection: local - strategy: free - gather_facts: false - vars: - base_path: "{{ lookup('env', 'REPO_ANSIBLE_BASE_PATH') or (playbook_dir + '/workspace') }}" - repo_path: "{{ base_path }}/{{ inventory_hostname }}" - tasks: - - import_tasks: tasks/retrieve-validate-repo-data.yaml - - - import_tasks: tasks/pull-request.yaml diff --git a/playbook-push.yaml b/playbook-push.yaml deleted file mode 100644 index 0c4c421..0000000 --- a/playbook-push.yaml +++ /dev/null @@ -1,11 +0,0 @@ -- hosts: all - connection: local - strategy: free - gather_facts: false - vars: - base_path: "{{ lookup('env', 'REPO_ANSIBLE_BASE_PATH') or (playbook_dir + '/workspace') }}" - repo_path: "{{ base_path }}/{{ inventory_hostname }}" - tasks: - - import_tasks: tasks/retrieve-validate-repo-data.yaml - - - import_tasks: tasks/push.yaml From 6d755122275afef95a1196df1052c87b81c791cc Mon Sep 17 00:00:00 2001 From: Marius Ghita Date: Sat, 25 Jan 2025 18:07:55 +0200 Subject: [PATCH 5/6] docs: bulk-apply flags and options #0000 --- bulk-apply.yaml | 3 +++ docs/BulkOperations.md | 38 ++++++++++++++++++++++++-------------- 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/bulk-apply.yaml b/bulk-apply.yaml index 72d55fe..8d01974 100644 --- a/bulk-apply.yaml +++ b/bulk-apply.yaml @@ -11,6 +11,7 @@ repository: "{{ inventory_hostname }}" destination: "{{ repo_path }}" when: not skip_checkout + tags: checkout - import_tasks: tasks/version-migrations.yaml - import_tasks: tasks/retrieve-validate-repo-data.yaml @@ -39,6 +40,8 @@ - import_tasks: tasks/pull-request.yaml when: changes == 'pull-request' + tags: commit-changes - import_tasks: tasks/push.yaml when: changes == 'push' + tags: commit-changes diff --git a/docs/BulkOperations.md b/docs/BulkOperations.md index 2e1d6bb..8f981a1 100644 --- a/docs/BulkOperations.md +++ b/docs/BulkOperations.md @@ -1,9 +1,9 @@ -The repository contains playbooks that can simultaneously operate across multiple repositories (e.g., `bulk-apply.yaml`). +The repository contains the bulk-apply playbook that can simultaneously operate across multiple repositories. These bulk operations require an inventory file that makes up the "hosts" upon which it should operate. In this -context, the hosts are the names of the repositories, which should be in an automatic fashion: checked out, modified per -their `repo.yaml` configuration file, and push these changes upstream. +context, the hosts are the repository names, which will be: checked out, modified per +their `repo.yaml` configuration file, and commited back upstream. **Install the [GitHub CLI](https://cli.github.com/) and [jq](https://jqlang.github.io/jq/) dependencies.** @@ -20,17 +20,25 @@ gh search repos --owner=linkorb --limit=1000 \ | tee generated-inventory.ini ``` -> **Note** `generated-inventory.ini` is part of `.gitignore` to avoid accidental file commits. +> **Note** `generated-inventory.ini` file is part of `.gitignore` to avoid accidental file commits. -> An entry within the inventory is of the form `REPOSITORY_NAME ansible_host=localhost` +> An entry within the inventory follows the form `REPOSITORY_NAME ansible_host=localhost` -#### Run a playbook in bulk -You can selectively run the playbooks defined within this repository. For example you -could check them all out within the `./workspace/` directory (by default) using: +#### Bulk apply repo-ansible + + +```shell +ansible-playbook -i generated-inventory.ini bulk-apply.yaml +``` + +#### Running select sections of bulk-apply.yaml + +For example you can check out all repositories defined in the inventory to the `./workspace/` directory using: ```shell -ansible-playbook -i generated-inventory.ini playbook-checkout.yaml +ansible-playbook -i generated-inventory.ini \ + --tags checkout bulk-apply.yaml ``` > [!NOTE] @@ -40,22 +48,24 @@ ansible-playbook -i generated-inventory.ini playbook-checkout.yaml > `REPO_ANSIBLE_BASE_PATH` environment variable. The changes can be committed back upstream using either pull requests or directly pushing a commit into the -default branch. Via specific playbooks: +default branch. ```shell -ansible-playbook -i generated-inventory.ini playbook-pull-request.yaml +ansible-playbook -i generated-inventory.ini \ + --tags commit-changes -e changes=pull-request bulk-apply.yaml ``` ```shell -ansible-playbook -i generated-inventory.ini playbook-push.yaml +ansible-playbook -i generated-inventory.ini \ + --tags commit-changes -e changes=push bulk-apply.yaml ``` -Alternatively, when `playbook-all.yaml` is executed, the `REPO_ANSIBLE_CHANGES` environment variable can be set to +Alternatively, when `bulk-apply.yaml` is executed, the `REPO_ANSIBLE_CHANGES` environment variable can be set to either `pull-request`, or `push` to invoke the desired commit path to be taken (by default, this step is skipped). #### Bulk apply across repositories and create pull requests with changes ```shell REPO_ANSIBLE_CHANGES=pull-request \ - ansible-playbook -i generated-inventory.ini playbook-all.yaml + ansible-playbook -i generated-inventory.ini bulk-apply.yaml ``` From c8c1dc1ca8fbc07eb3fe7b0fbed2200136eb100b Mon Sep 17 00:00:00 2001 From: Marius Ghita Date: Sat, 25 Jan 2025 18:12:21 +0200 Subject: [PATCH 6/6] chore: manually bump repo.yaml version #0000 --- repo.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/repo.yaml b/repo.yaml index ea7066a..1baa3e6 100644 --- a/repo.yaml +++ b/repo.yaml @@ -15,5 +15,5 @@ license: mit license_year: 2024 name: repo-ansible type: other -version: v0.11.0 +version: v0.11.1 visibility: public