From a630816f1c4709f5fc1dfa4017511fde77fe97a3 Mon Sep 17 00:00:00 2001 From: dede Date: Sat, 28 Dec 2024 12:51:31 +0100 Subject: [PATCH] conf(dev): add workspace file, setup script and requirements files --- .gitignore | 1 - ansible-common.code-workspace | 27 +++++++++++++ requirements-freeze.txt | 30 ++++++++++++++ requirements.txt | 2 + setup.sh | 74 +++++++++++++++++++++++++++++++++++ 5 files changed, 133 insertions(+), 1 deletion(-) create mode 100644 ansible-common.code-workspace create mode 100644 requirements-freeze.txt create mode 100644 requirements.txt create mode 100755 setup.sh diff --git a/.gitignore b/.gitignore index b258781..1888623 100644 --- a/.gitignore +++ b/.gitignore @@ -13,7 +13,6 @@ test.yml !.vscode/tasks.json !.vscode/launch.json !.vscode/extensions.json -*.code-workspace # Local History for Visual Studio Code .history/ diff --git a/ansible-common.code-workspace b/ansible-common.code-workspace new file mode 100644 index 0000000..d7c6b26 --- /dev/null +++ b/ansible-common.code-workspace @@ -0,0 +1,27 @@ +{ + "folders": [ + { + "path": "." + } + ], + "settings": { + "files.associations": { + "*.yml": "ansible", + "*.j2": "ansible-jinja" + }, + "ansible.python.interpreterPath": "${workspaceFolder}/.venv/bin/python", + "python.defaultInterpreterPath": "${workspaceFolder}/.venv/bin/python", + "editor.tabSize": 2, + "trailing-spaces.highlightCurrentLine": false, + "trailing-spaces.schemeIgnore": [ + "markdown", + "output" + ] + }, + "extensions": { + "recommendations": [ + "redhat.ansible", + "shardulm94.trailing-spaces" + ] + } +} \ No newline at end of file diff --git a/requirements-freeze.txt b/requirements-freeze.txt new file mode 100644 index 0000000..e7902bf --- /dev/null +++ b/requirements-freeze.txt @@ -0,0 +1,30 @@ +ansible==11.1.0 +ansible-compat==24.10.0 +ansible-core==2.18.1 +ansible-lint==24.12.2 +attrs==24.3.0 +black==24.10.0 +bracex==2.5.post1 +cffi==1.17.1 +click==8.1.8 +cryptography==44.0.0 +filelock==3.16.1 +importlib_metadata==8.5.0 +Jinja2==3.1.5 +jsonschema==4.23.0 +jsonschema-specifications==2024.10.1 +MarkupSafe==3.0.2 +mypy-extensions==1.0.0 +packaging==24.2 +pathspec==0.12.1 +platformdirs==4.3.6 +pycparser==2.22 +PyYAML==6.0.2 +referencing==0.35.1 +resolvelib==1.0.1 +rpds-py==0.22.3 +ruamel.yaml==0.18.6 +subprocess-tee==0.4.2 +wcmatch==10.0 +yamllint==1.35.1 +zipp==3.21.0 diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..ea8a68f --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +ansible +ansible-lint diff --git a/setup.sh b/setup.sh new file mode 100755 index 0000000..249fb41 --- /dev/null +++ b/setup.sh @@ -0,0 +1,74 @@ +#!/bin/bash + +# exit immediately if a command exits with a non-zero status +set -e + +VENV_DIR=.venv + +# define color codes for output +RED=$(tput setaf 1) +GREEN=$(tput setaf 2) +YELLOW=$(tput setaf 3) +BLUE=$(tput setaf 4; tput bold) +NC=$(tput sgr0) # no color + +# function to check for required commands +check_command() { + command -v "$1" >/dev/null 2>&1 || { + echo -e "${RED}error: $1 is not installed. please install it and try again.${NC}" >&2; + exit 1; + } +} + +# function to install the latest python +install_python() { + echo -e "${BLUE}installing the latest python...${NC}" + sudo pacman -S python --noconfirm +} + +# function to create a virtual environment +create_virtualenv() { + check_command "python" + echo -e "${BLUE}creating virtual environment...${NC}" + if [ ! -d "$VENV_DIR" ]; then + python -m venv $VENV_DIR + echo -e "${GREEN}virtual environment created at $VENV_DIR${NC}" + else + echo -e "${YELLOW}virtual environment already exists at $VENV_DIR${NC}" + fi +} + +# function to install python requirements +install_requirements() { + check_command "pip" + echo -e "${BLUE}installing python requirements from requirements-freeze.txt...${NC}" + source $VENV_DIR/bin/activate + pip install --upgrade pip + if [ -f "requirements-freeze.txt" ]; then + pip install -r requirements-freeze.txt + else + echo -e "${YELLOW}requirements-freeze.txt not found. skipping python requirements installation.${NC}" + fi + deactivate +} + +# function to install ansible roles from requirements.yml +install_ansible_requirements() { + check_command "ansible-galaxy" + echo -e "${BLUE}installing ansible roles from requirements.yml...${NC}" + if [ -f "requirements.yml" ]; then + source $VENV_DIR/bin/activate + ansible-galaxy install -r requirements.yml + deactivate + else + echo -e "${YELLOW}requirements.yml not found. skipping ansible requirements installation.${NC}" + fi +} + +# main script execution +install_python # install the latest python +create_virtualenv # create a virtual environment +install_requirements # install python requirements +install_ansible_requirements # install ansible requirements + +echo -e "${GREEN}setup completed successfully!${NC}"