From d70dab28fbea865950184a328c56516eb5d467f2 Mon Sep 17 00:00:00 2001 From: Ruairidh MacLeod Date: Wed, 29 Nov 2023 17:05:31 +0000 Subject: [PATCH] refactor scripts to inventories --- bin/build-docker-aio | 12 +----------- bin/start-docker-services | 12 +++++++----- bin/stop-docker-services | 12 +++++++----- inventories/docker-aio/group_vars/all.yml | 5 +++++ inventories/docker-aio/hosts.ini | 10 ++++++++++ inventories/local/hosts.ini | 10 ++++++++-- site.yml | 4 ++-- 7 files changed, 40 insertions(+), 25 deletions(-) create mode 100644 inventories/docker-aio/group_vars/all.yml create mode 100644 inventories/docker-aio/hosts.ini diff --git a/bin/build-docker-aio b/bin/build-docker-aio index 73324ac..e6dd5aa 100755 --- a/bin/build-docker-aio +++ b/bin/build-docker-aio @@ -10,17 +10,7 @@ docker container rm -f "${CONTAINER_NAME}" || true docker run --rm -d --name "${CONTAINER_NAME}" "${IMAGE}:build" ansible-playbook \ - --connection docker \ - --inventory "${CONTAINER_NAME}," \ - --limit "${CONTAINER_NAME}" \ - -e "ansible_python_interpreter=python3.10" \ - -e "smi_preflight_group_name=smi" \ - -e "smi_preflight_allow_create_group=true" \ - -e "host_role='Docker AIO'" \ - -e "smi_service_software_allow_create_install_dir=true" \ - -e "smi_service_software_allow_create_logs_dir=true" \ - -e "smi_service_software_allow_create_pacs_dir=true" \ - -e "smi_service_software_allow_create_extract_dir=true" \ + --inventory inventories/docker-aio/hosts.ini \ "${@}" \ site.yml diff --git a/bin/start-docker-services b/bin/start-docker-services index 4c22ec8..49fe8d5 100755 --- a/bin/start-docker-services +++ b/bin/start-docker-services @@ -2,12 +2,14 @@ set -euxo pipefail +# NOTE(rkm 2023-11-29) Use the current python interpreter instead +# of the system default +local_python="$(command -v python || true)" + ansible-playbook \ - --connection local \ - --inventory "localhost," \ - -e "ansible_python_interpreter=$(command -v python || true)" \ - -e "smi_preflight_group_name=${USER}" \ + --inventory inventories/local/hosts.ini \ + -e "ansible_python_interpreter=${local_python}" \ -e "smi_docker_services_state=present" \ - --tags docker \ + --tags none,docker \ "${@}" \ site.yml diff --git a/bin/stop-docker-services b/bin/stop-docker-services index bf7b649..73eae89 100755 --- a/bin/stop-docker-services +++ b/bin/stop-docker-services @@ -2,12 +2,14 @@ set -euxo pipefail +# NOTE(rkm 2023-11-29) Use the current python interpreter instead +# of the system default +local_python="$(command -v python || true)" + ansible-playbook \ - --connection local \ - --inventory "localhost," \ - -e "ansible_python_interpreter=$(command -v python || true)" \ - -e "smi_preflight_group_name=${USER}" \ + --inventory inventories/local/hosts.ini \ + -e "ansible_python_interpreter=${local_python}" \ -e "smi_docker_services_state=absent" \ - --tags docker \ + --tags none,docker \ "${@}" \ site.yml diff --git a/inventories/docker-aio/group_vars/all.yml b/inventories/docker-aio/group_vars/all.yml new file mode 100644 index 0000000..eedf66e --- /dev/null +++ b/inventories/docker-aio/group_vars/all.yml @@ -0,0 +1,5 @@ +--- +smi_preflight_group_name: smi +smi_fs_software_root: "/opt/epcc/smi/software" +smi_fs_data_root: "/opt/epcc/smi/data" +smi_base_dirs_allow_create_dirs: true diff --git a/inventories/docker-aio/hosts.ini b/inventories/docker-aio/hosts.ini new file mode 100644 index 0000000..2e57d18 --- /dev/null +++ b/inventories/docker-aio/hosts.ini @@ -0,0 +1,10 @@ +[all] +docker_aio_build + +[all:vars] +ansible_connection=docker +ansible_python_interpreter=python3.10 +host_role='Docker AIO' + +[file_server] +docker_aio_build diff --git a/inventories/local/hosts.ini b/inventories/local/hosts.ini index 715ab76..2efc276 100644 --- a/inventories/local/hosts.ini +++ b/inventories/local/hosts.ini @@ -1,5 +1,11 @@ [all] -localhost ansible_connection=local +localhost + +[all:vars] +ansible_connection=local + +[file_server] +localhost -[primary_file_server] +[docker_host] localhost diff --git a/site.yml b/site.yml index 9c28dd8..1247b79 100644 --- a/site.yml +++ b/site.yml @@ -11,12 +11,12 @@ - 01-system tags: [system] - name: Start Docker services - hosts: all + hosts: docker_host roles: - 02-docker-services tags: [never, docker] - name: Install service software on primary file server - hosts: primary_file_server,smi_aio_build + hosts: file_server pre_tasks: - name: Assert required variables are defined ansible.builtin.assert: