From adca05a2a20e6d37051307133430c4fcf73ed94e Mon Sep 17 00:00:00 2001 From: Aine Date: Mon, 12 Aug 2024 13:45:28 +0300 Subject: [PATCH] adjust 'just update' and 'just roles' commands similar to mdad. --- docs/configuring-playbook.md | 2 +- docs/installing.md | 2 +- docs/prerequisites.md | 2 +- justfile | 25 ++++++++++++++++++++++--- 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/docs/configuring-playbook.md b/docs/configuring-playbook.md index 5df648d..7025e9e 100644 --- a/docs/configuring-playbook.md +++ b/docs/configuring-playbook.md @@ -11,7 +11,7 @@ You can then follow these steps inside the playbook directory: 2. copy the sample configuration file (`cp examples/vars.yml inventory/host_vars//vars.yml`) -3. edit the configuration file (`inventory/host_vars//vars.yml`) to your liking. You should [enable one or more services](supported-services.md) in your `vars.yml` file. You may also take a look at the various `roles/**/ROLE_NAME_HERE/defaults/main.yml` files (after importing external roles with `just roles` into `roles/galaxy`) and see if there's something you'd like to copy over and override in your `vars.yml` configuration file. +3. edit the configuration file (`inventory/host_vars//vars.yml`) to your liking. You should [enable one or more services](supported-services.md) in your `vars.yml` file. You may also take a look at the various `roles/**/ROLE_NAME_HERE/defaults/main.yml` files (after importing external roles with `just update` into `roles/galaxy`) and see if there's something you'd like to copy over and override in your `vars.yml` configuration file. 4. copy the sample inventory hosts file (`cp examples/hosts inventory/hosts`) diff --git a/docs/installing.md b/docs/installing.md index c78aa78..1094ebe 100644 --- a/docs/installing.md +++ b/docs/installing.md @@ -9,7 +9,7 @@ We recommend installing and using using `just` - otherwise, you'll need to do mo - (only if you're not using the [`just`](https://github.com/casey/just) utility): create `setup.yml`, `requirements.yml` and `group_vars/mash_servers` based on the up-to-date templates found in the [`templates/` directory](../templates). If you are using `just`, these files are created and maintained up-to-date automatically. -- update the Ansible roles in this playbook by running `just roles`. `just roles` is a shortcut which ultimately runs [ansible-galaxy](https://docs.ansible.com/ansible/latest/cli/ansible-galaxy.html) to download Ansible roles defined in the `requirements.yml` file. If you don't have `just`, you can also manually run the `roles` commands seen in the [`justfile`](../justfile). +- update the Ansible roles in this playbook by either running `just update` or `git pull && just roles`. `just update` is a shortcut that calls `git pull` and `just roles` with a single command, while `just roles` is a shortcut which ultimately runs either [agru](https://github.com/etkecc/agru) or [ansible-galaxy](https://docs.ansible.com/ansible/latest/cli/ansible-galaxy.html) to download Ansible roles defined in the `requirements.yml` file. If you don't have `just`, you can also manually run the `roles` commands seen in the [`justfile`](../justfile). ## Playbook tags introduction diff --git a/docs/prerequisites.md b/docs/prerequisites.md index 56a3891..dafca59 100644 --- a/docs/prerequisites.md +++ b/docs/prerequisites.md @@ -26,7 +26,7 @@ If your distro runs within an [LXC container](https://linuxcontainers.org/), you - [git](https://git-scm.com/) is the recommended way to download the playbook to your computer. `git` may also be required on the server if you will be [self-building](self-building.md) components. -- [just](https://github.com/casey/just) for running `just roles` and playbook installation commands, etc. (see [`justfile`](../justfile)). You can get by without `just` (by running `ansible-galaxy`, `ansible-playbook` commands manually), but maintaining your playbook setup will require more manual work. `just` (thanks to the commands defined in the `justfile`) keeps various files (`setup.yml`, `requirements.yml`, `group_vars/mash_servers`) up-to-date with the templates in [the `templates/` directory](../templates/) automatically. +- [just](https://github.com/casey/just) for running `just update` and playbook installation commands, etc. (see [`justfile`](../justfile)). You can get by without `just` (by running `ansible-galaxy`, `ansible-playbook` commands manually), but maintaining your playbook setup will require more manual work. `just` (thanks to the commands defined in the `justfile`) keeps various files (`setup.yml`, `requirements.yml`, `group_vars/mash_servers`) up-to-date with the templates in [the `templates/` directory](../templates/) automatically. - at least one domain name you can use diff --git a/justfile b/justfile index 0c2d9f8..8febafc 100644 --- a/justfile +++ b/justfile @@ -12,6 +12,7 @@ roles: _requirements-yml if [ -x "$(command -v agru)" ]; then agru -r {{ justfile_directory() }}/requirements.yml else + echo "[NOTE] You are using the standard ansible-galaxy tool to install roles, which is slow and lacks other features. We recommend installing the 'agru' tool to speed up the process: https://github.com/etkecc/agru#where-to-get" rm -rf roles/galaxy ansible-galaxy install -r {{ justfile_directory() }}/requirements.yml -p roles/galaxy/ --force fi @@ -68,9 +69,27 @@ _optimize-for-var-paths +PATHS: --src-group-vars-yml-path={{ templates_directory_path }}/group_vars_mash_servers \ --dst-group-vars-yml-path={{ justfile_directory() }}/group_vars/mash_servers -# Updates requirements.yml if there are any new tags available. Requires agru -update: && opml versions - @agru -r {{ templates_directory_path }}/requirements.yml -u +# Updates the playbook and installs the necessary Ansible roles pinned in requirements.yml. If a -u flag is passed, also updates the requirements.yml file with new role versions (if available) +update *flags: update-playbook-only + #!/usr/bin/env sh + if [ -x "$(command -v agru)" ]; then + echo {{ if flags == "" { "Installing roles pinned in requirements.yml..." } else if flags == "-u" { "Updating roles and pinning new versions in requirements.yml..." } else { "Unknown flags passed" } }} + agru -r {{ templates_directory_path }}/requirements.yml {{ flags }} + just --justfile {{ justfile() }} versions + just --justfile {{ justfile() }} opml + else + echo "[NOTE] You are using the standard ansible-galaxy tool to install roles, which is slow and lacks other features. We recommend installing the 'agru' tool to speed up the process: https://github.com/etkecc/agru#where-to-get" + echo "Installing roles..." + rm -rf roles/galaxy + ansible-galaxy install -r requirements.yml -p roles/galaxy/ --force + fi + +# Updates the playbook without installing/updating Ansible roles +update-playbook-only: + @echo "Updating playbook..." + @git stash -q + @git pull -q + @-git stash pop -q # Runs ansible-lint against all roles in the playbook lint: