diff --git a/.github/workflows/update-readme.yaml b/.github/workflows/auto-update-readme.yaml similarity index 91% rename from .github/workflows/update-readme.yaml rename to .github/workflows/auto-update-readme.yaml index 562366f..e803ea4 100644 --- a/.github/workflows/update-readme.yaml +++ b/.github/workflows/auto-update-readme.yaml @@ -18,13 +18,13 @@ 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 - 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/playbook-all.yaml b/bulk-apply.yaml similarity index 95% rename from playbook-all.yaml rename to bulk-apply.yaml index 22a52c6..8d01974 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 }}" @@ -12,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 @@ -40,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 044a917..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., `playbook-all.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 ``` 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] ************************************************************************** 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 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