From 9d73f645cd190b1b980bab6b73488a064849c82f Mon Sep 17 00:00:00 2001 From: terra Date: Tue, 27 Aug 2024 15:00:22 +0300 Subject: [PATCH] no message --- .github/actions/testing-action/action.yml | 17 +- .github/workflows/main.yml | 18 ++ .github/workflows/reusable-workflow.yml | 0 .gitignore | 9 - .vagrant/bundler/global.sol | 1 + .../machines/default/aws/action_provision | 1 + .vagrant/machines/default/aws/box_meta | 1 + .vagrant/machines/default/aws/creator_uid | 1 + .vagrant/machines/default/aws/id | 1 + .vagrant/machines/default/aws/index_uuid | 1 + .vagrant/machines/default/aws/synced_folders | 1 + .vagrant/machines/default/aws/vagrant_cwd | 1 + .vagrant/rgloader/loader.rb | 12 ++ parameters_accepts.sh | 163 ------------------ parameters_exist.sh | 2 + parameters_find.sh | 60 ------- 16 files changed, 53 insertions(+), 236 deletions(-) create mode 100644 .github/workflows/reusable-workflow.yml delete mode 100644 .gitignore create mode 100644 .vagrant/bundler/global.sol create mode 100644 .vagrant/machines/default/aws/action_provision create mode 100644 .vagrant/machines/default/aws/box_meta create mode 100644 .vagrant/machines/default/aws/creator_uid create mode 100644 .vagrant/machines/default/aws/id create mode 100644 .vagrant/machines/default/aws/index_uuid create mode 100644 .vagrant/machines/default/aws/synced_folders create mode 100644 .vagrant/machines/default/aws/vagrant_cwd create mode 100644 .vagrant/rgloader/loader.rb delete mode 100644 parameters_accepts.sh delete mode 100644 parameters_find.sh diff --git a/.github/actions/testing-action/action.yml b/.github/actions/testing-action/action.yml index 48c13bd..b80cdbe 100644 --- a/.github/actions/testing-action/action.yml +++ b/.github/actions/testing-action/action.yml @@ -1,15 +1,24 @@ -name: "Echo Greeting Action" -description: "A simple action that echoes a greeting message." +# .github/actions/print-message/action.yml +name: "Print Message Action" +description: "A simple action to print a message and greet a person." inputs: name: description: "The name of the person to greet" required: true default: "World" + message: + description: "A custom message to print" + required: true runs: - using: "composite" # Allows you to define a sequence of shell commands + using: "composite" steps: - name: Echo the greeting shell: bash run: | - echo "Hello, ${{ inputs.name }}!" \ No newline at end of file + echo "Hello, ${{ inputs.name }}!" + + - name: Print the custom message + shell: bash + run: | + echo "Message: ${{ inputs.message }}" diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 23da6d9..5645a09 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -21,3 +21,21 @@ jobs: uses: ./.github/actions/testing-action with: name: 'koshmarik' + + # Job to call the composite action + call-composite-action: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Run composite action + uses: ./.github/actions/print-message + with: + message: "Hello from composite action!" + + # Job to call the reusable workflow + call-reusable-workflow: + uses: ./.github/workflows/reusable-workflow.yml + with: + message: "Hello from reusable workflow!" \ No newline at end of file diff --git a/.github/workflows/reusable-workflow.yml b/.github/workflows/reusable-workflow.yml new file mode 100644 index 0000000..e69de29 diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 2a9474a..0000000 --- a/.gitignore +++ /dev/null @@ -1,9 +0,0 @@ -/**/.* -/**/.*/ -!/.gitignore -*-test.* -main.sh -main.yml -goldenimage_script.sh -manifest.json -goldenimage_result.json \ No newline at end of file diff --git a/.vagrant/bundler/global.sol b/.vagrant/bundler/global.sol new file mode 100644 index 0000000..9d4ceef --- /dev/null +++ b/.vagrant/bundler/global.sol @@ -0,0 +1 @@ +{"dependencies":[["aws-eventstream",["~> 1",">= 1.0.2"]],["aws-sigv4",["~> 1.0"]],["jmespath",["~> 1.0"]],["aws-sdk-core",["= 2.11.632"]],["aws-sdk-resources",["= 2.11.632"]],["aws-sdk",["= 2.11.632"]],["iniparse",["~> 1.4",">= 1.4.2"]],["webrick",[">= 0"]],["xmlrpc",[">= 0"]],["formatador",["~> 0.2"]],["excon",["~> 0.58"]],["builder",[">= 0"]],["fog-core",["~> 1.45"]],["racc",["~> 1.4"]],["nokogiri",[">= 1.5.11","< 2.0.0"]],["fog-xml",["~> 0.1.1"]],["fog-xenserver",[">= 0"]],["optimist",["~> 3.0"]],["json",["~> 2.0"]],["rbvmomi2",["~> 3.0"]],["fog-vsphere",[">= 0.4.0"]],["fog-voxel",[">= 0"]],["CFPropertyList",["~> 2.2"]],["fission",[">= 0"]],["fog-vmfusion",[">= 0"]],["fog-terremark",[">= 0"]],["multi_json",["~> 1.10"]],["fog-json",[">= 0"]],["fog-storm_on_demand",[">= 0"]],["fog-softlayer",[">= 0"]],["fog-serverlove",[">= 0"]],["fog-sakuracloud",[">= 0.0.4"]],["fog-riakcs",[">= 0"]],["fog-radosgw",[">= 0.0.2"]],["ipaddress",["~> 0.5"]],["fog-rackspace",[">= 0"]],["fog-profitbricks",[">= 0"]],["fog-powerdns",[">= 0.1.1"]],["ovirt-engine-sdk",[">= 4.3.1"]],["bigdecimal",[">= 0"]],["mutex_m",[">= 0"]],["ruby2_keywords",[">= 0"]],["drb",[">= 0"]],["base64",[">= 0"]],["minitest",[">= 5.1"]],["connection_pool",[">= 2.2.5"]],["concurrent-ruby",["~> 1.0",">= 1.0.2"]],["tzinfo",["~> 2.0"]],["i18n",[">= 1.6","< 2"]],["activesupport",[">= 0"]],["fog-ovirt",[">= 0"]],["fog-openstack",[">= 0"]],["fog-local",[">= 0"]],["fog-joyent",[">= 0"]],["fog-internet-archive",[">= 0"]],["fog-google",["<= 0.1.0"]],["fog-ecloud",["~> 0.1"]],["fog-dynect",["~> 0.0.2"]],["fog-dnsimple",["~> 1.0"]],["fog-digitalocean",[">= 0.3.0"]],["fog-cloudatcost",["~> 0.1.0"]],["mime-types-data",["~> 3.2015"]],["mime-types",[">= 0"]],["dry-inflector",[">= 0"]],["fog-brightbox",["~> 0.4"]],["fog-aws",[">= 0.6.0"]],["fog-atmos",[">= 0"]],["rexml",[">= 0"]],["xml-simple",["~> 1.1"]],["netrc",["~> 0.8"]],["domain_name",["~> 0.5"]],["http-cookie",[">= 1.0.2","< 2.0"]],["http-accept",[">= 1.7.0","< 2.0"]],["rest-client",["~> 2.0"]],["aliyun-sdk",["~> 0.8.0"]],["public_suffix",[">= 2.0.2","< 6.0"]],["addressable",["~> 2.8.0"]],["fog-aliyun",[">= 0.1.0"]],["fog",["~> 1.22"]],["vagrant-aws",["= 0.7.2"]],["vagrant-aws-credentials",["= 0.1.4"]]],"checksum":"6fa2d676c1f666f0e38c9f3fdf5e1de86ecf5e6fcb32f39b55191baf9c2dd63c","vagrant_version":"2.4.1"} \ No newline at end of file diff --git a/.vagrant/machines/default/aws/action_provision b/.vagrant/machines/default/aws/action_provision new file mode 100644 index 0000000..528df11 --- /dev/null +++ b/.vagrant/machines/default/aws/action_provision @@ -0,0 +1 @@ +1.5:i-02d38e912de59075a \ No newline at end of file diff --git a/.vagrant/machines/default/aws/box_meta b/.vagrant/machines/default/aws/box_meta new file mode 100644 index 0000000..250ad4c --- /dev/null +++ b/.vagrant/machines/default/aws/box_meta @@ -0,0 +1 @@ +{"name":"dummy","version":"0","provider":"aws","directory":"boxes/dummy/0/aws"} \ No newline at end of file diff --git a/.vagrant/machines/default/aws/creator_uid b/.vagrant/machines/default/aws/creator_uid new file mode 100644 index 0000000..ec52cb8 --- /dev/null +++ b/.vagrant/machines/default/aws/creator_uid @@ -0,0 +1 @@ +501 \ No newline at end of file diff --git a/.vagrant/machines/default/aws/id b/.vagrant/machines/default/aws/id new file mode 100644 index 0000000..cd73f61 --- /dev/null +++ b/.vagrant/machines/default/aws/id @@ -0,0 +1 @@ +i-02d38e912de59075a \ No newline at end of file diff --git a/.vagrant/machines/default/aws/index_uuid b/.vagrant/machines/default/aws/index_uuid new file mode 100644 index 0000000..e4d1bf1 --- /dev/null +++ b/.vagrant/machines/default/aws/index_uuid @@ -0,0 +1 @@ +57a151f954ac431594291d457ce7122a \ No newline at end of file diff --git a/.vagrant/machines/default/aws/synced_folders b/.vagrant/machines/default/aws/synced_folders new file mode 100644 index 0000000..390ed81 --- /dev/null +++ b/.vagrant/machines/default/aws/synced_folders @@ -0,0 +1 @@ +{"rsync":{"/vagrant":{"guestpath":"/vagrant","hostpath":"/Users/terragootman/git/opinion-ansible/testing","disabled":false,"__vagrantfile":true,"owner":"ec2-user","group":"ec2-user"}}} \ No newline at end of file diff --git a/.vagrant/machines/default/aws/vagrant_cwd b/.vagrant/machines/default/aws/vagrant_cwd new file mode 100644 index 0000000..5b2678b --- /dev/null +++ b/.vagrant/machines/default/aws/vagrant_cwd @@ -0,0 +1 @@ +/Users/terragootman/git/opinion-ansible/testing \ No newline at end of file diff --git a/.vagrant/rgloader/loader.rb b/.vagrant/rgloader/loader.rb new file mode 100644 index 0000000..b6c81bf --- /dev/null +++ b/.vagrant/rgloader/loader.rb @@ -0,0 +1,12 @@ +# Copyright (c) HashiCorp, Inc. +# SPDX-License-Identifier: BUSL-1.1 + +# This file loads the proper rgloader/loader.rb file that comes packaged +# with Vagrant so that encoded files can properly run with Vagrant. + +if ENV["VAGRANT_INSTALLER_EMBEDDED_DIR"] + require File.expand_path( + "rgloader/loader", ENV["VAGRANT_INSTALLER_EMBEDDED_DIR"]) +else + raise "Encoded files can't be read outside of the Vagrant installer." +end diff --git a/parameters_accepts.sh b/parameters_accepts.sh deleted file mode 100644 index 569dd45..0000000 --- a/parameters_accepts.sh +++ /dev/null @@ -1,163 +0,0 @@ -#!/usr/bin/env bash -# Constants -LOCAL_IDENTIFY_OS_SCRIPT="identify_os.sh" -REMOTE_IDENTIFY_OS_SCRIPT="https://raw.githubusercontent.com/inqwise/ansible-automation-toolkit/default/identify_os.sh" -VAULT_PASSWORD_FILE="vault_password" -PLAYBOOK_VERSION="latest" -PIP_COMMAND="pip" - -REGION="" -GET_PIP_URL="" -PLAYBOOK_NAME="" -PLAYBOOK_BASE_URL="" -VAULT_PASSWORD="" - -usage() { - echo "Usage: $0 [--token ] [--get_pip_url ] [--playbook_name ] [--playbook_base_url ] [-r ] [--account_id ] [--topic_name ] [--vault_password ]" - exit 1 -} - -while getopts ":r:-:" option; do - case "${option}" in - r) REGION=${OPTARG};; - -) - case "${OPTARG}" in - get_pip_url) GET_PIP_URL="${!OPTIND}"; OPTIND=$((OPTIND + 1));; - playbook_name) PLAYBOOK_NAME="${!OPTIND}"; OPTIND=$((OPTIND + 1));; - playbook_base_url) PLAYBOOK_BASE_URL="${!OPTIND}"; OPTIND=$((OPTIND + 1));; - vault_password) VAULT_PASSWORD="${!OPTIND}"; OPTIND=$((OPTIND + 1));; - *) echo "Invalid option --${OPTARG}"; usage;; - esac - ;; - \?) echo "Invalid option: -${OPTARG}" >&2; usage;; - :) echo "Option -${OPTARG} requires an argument." >&2; usage;; - esac -done - -# Functions -assert_var() { - local var_name="$1" - local var_value="$2" - if [ -z "$var_value" ]; then - echo "Error: $var_name is not set." >&2 - exit 1 - fi -} - -# Global Variables -PYTHON_BIN=python3 -MAIN_SCRIPT_URL="" - -identify_os() { - echo 'identify_os' - if [ -z "${OS_FAMILY:-}" ]; then - echo "OS_FAMILY is not defined." - if [ -f "$LOCAL_IDENTIFY_OS_SCRIPT" ]; then - echo "Executing local identify_os.sh..." - source "$LOCAL_IDENTIFY_OS_SCRIPT" - else - echo "Local identify_os.sh not found. Executing from remote URL..." - source <(curl -s "$REMOTE_IDENTIFY_OS_SCRIPT") - fi - fi -} - -cleanup() { - if [ -f "$VAULT_PASSWORD_FILE" ]; then - rm -f "$VAULT_PASSWORD_FILE" - echo "vault_password file removed." - fi -} - -catch_error() { - echo "An error occurred in goldenimage_script: '$1'" - cleanup -} - -setup_environment() { - echo 'setup_environment' - sudo mkdir /deployment - sudo chown -R "$(whoami)": /deployment - - if [[ "$OS_FAMILY" == "amzn" && "$OS_VERSION" -eq 2 ]]; then - echo 'amzn2 tweaks' - PYTHON_BIN="python3.8" - MAIN_SCRIPT_URL="https://raw.githubusercontent.com/inqwise/ansible-automation-toolkit/default/main_amzn2.sh" - sudo yum -y erase python3 && sudo amazon-linux-extras install $PYTHON_BIN - else - MAIN_SCRIPT_URL="https://raw.githubusercontent.com/inqwise/ansible-automation-toolkit/default/main_amzn2023.sh" - fi - - $PYTHON_BIN -m venv /deployment/ansibleenv - source /deployment/ansibleenv/bin/activate -} - -install_pip() { - echo 'install_pip' - local url=$1 - if [[ $url == s3://* ]]; then - echo "Downloading get-pip from S3..." - aws s3 cp "$url" - | $PYTHON_BIN - elif [[ $url == http*://* ]]; then - echo "Downloading get-pip via HTTP..." - curl -s "$url" | $PYTHON_BIN - else - echo "Unsupported URL scheme: $url" >&2 - exit 1 - fi -} - -download_playbook() { - local base_url=$1 - local name=$2 - local local_folder=$3 - local s3_folder="$base_url/$name/$PLAYBOOK_VERSION" - - if aws s3 ls "$s3_folder" --region $REGION >/dev/null 2>&1; then - echo "download playbook '$s3_folder'" - mkdir "$local_folder" - aws s3 cp "$s3_folder/" "$local_folder" --recursive --region "$REGION" --exclude '.*' --exclude '*/.*' - chmod -R 755 "$local_folder" - else - echo "S3 folder $s3_folder does not exist. Exiting." >&2 - exit 1 - fi -} - -run_main_script() { - echo 'run_main_script' - cd /deployment/playbook - echo "$VAULT_PASSWORD" > "$VAULT_PASSWORD_FILE" - - if [ ! -f "main.sh" ]; then - echo "Local main.sh not found. Downloading main.sh script from URL..." - curl -s "$MAIN_SCRIPT_URL" -o main.sh - fi - - bash main.sh -e "playbook_name=$PLAYBOOK_NAME" --tags "installation" - cleanup -} - -main() { - set -euo pipefail - echo "Start goldenimage.sh" - - identify_os - - echo "playbook_name: $PLAYBOOK_NAME" - - assert_var "PLAYBOOK_NAME" "$PLAYBOOK_NAME" - assert_var "PLAYBOOK_BASE_URL" "$PLAYBOOK_BASE_URL" - assert_var "VAULT_PASSWORD" "$VAULT_PASSWORD" - assert_var "GET_PIP_URL" "$GET_PIP_URL" - assert_var "REGION" "$REGION" - - setup_environment - install_pip "$GET_PIP_URL" - download_playbook "$PLAYBOOK_BASE_URL" "$PLAYBOOK_NAME" /deployment/playbook - run_main_script - - echo "End goldenimage.sh" -} -# Execute the main function and capture errors -{ ERROR=$(main 2>&1 1>&$out); } {out}>&1 \ No newline at end of file diff --git a/parameters_exist.sh b/parameters_exist.sh index cb8b97f..946f2a1 100644 --- a/parameters_exist.sh +++ b/parameters_exist.sh @@ -19,6 +19,8 @@ echo "Playbook Base URL: $PLAYBOOK_BASE_URL" PLAYBOOK_NAME="ansible-openvpn" echo "playbook_name: $PLAYBOOK_NAME" +PLAYBOOK_VERSION="latest" + VAULT_PASSWORD="123123" bash parameters_accepts.sh --get_pip_url "$GET_PIP_URL" --playbook_name "$PLAYBOOK_NAME" --playbook_base_url "$PLAYBOOK_BASE_URL" -r "$REGION" --account_id "$ACCOUNT_ID" --topic_name "$TOPIC_NAME" --vault_password $VAULT_PASSWORD \ No newline at end of file diff --git a/parameters_find.sh b/parameters_find.sh deleted file mode 100644 index a2f9ce2..0000000 --- a/parameters_find.sh +++ /dev/null @@ -1,60 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -SECRET_NAME="vault_secret" - -get_region() { - ec2-metadata --availability-zone | sed -n 's/.*placement: \([a-zA-Z-]*[0-9]\).*/\1/p' -} - -get_account_id() { - aws sts get-caller-identity --query "Account" --output text -} - -get_parameter() { - local name=$1 - aws ssm get-parameter --name "$name" --query "Parameter.Value" --output text --region "$REGION" -} - -REGION=$(get_region) -echo "region: $REGION" - -PARAMETER=$(get_parameter "UserDataYAMLConfig") - -get_metadata_token() { - curl -s -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600" -} - -get_instance_tags() { - local token=$1 - local tag=$2 - local url="http://169.254.169.254/latest/meta-data/tags/instance/$tag" - - # Perform the curl request and capture the output and the HTTP status code - response=$(curl -s -o /dev/null -w "%{http_code}" -H "X-aws-ec2-metadata-token: $token" "$url") - - # Check if the status code is 200 - if [[ "$response" -eq 200 ]]; then - # If 200, fetch the actual tag value - curl -s -H "X-aws-ec2-metadata-token: $token" "$url" - else - echo "Error: Failed to retrieve instance tag $tag. HTTP status code: $response" >&2 - exit 1 - fi -} - -METADATA_TOKEN=$(get_metadata_token) - -PLAYBOOK_NAME=$(get_instance_tags "$METADATA_TOKEN" playbook_name) -echo "playbook_name: $PLAYBOOK_NAME" - -GET_PIP_URL=$(echo "$PARAMETER" | grep 'get_pip_url' | awk '{print $2}') -echo "Get Pip URL: $GET_PIP_URL" - -PLAYBOOK_BASE_URL=$(echo "$PARAMETER" | grep 'playbook_base_url' | awk '{print $2}') -echo "Playbook Base URL: $PLAYBOOK_BASE_URL" - -VAULT_PASSWORD=$(aws secretsmanager get-secret-value --secret-id "$SECRET_NAME" --region "$REGION" --query 'SecretString' --output text) - -curl -o /tmp/parameters_accepts.sh https://raw.githubusercontent.com/xXkoshmarikXx/test-commit/master/parameters_accepts.sh -bash /tmp/parameters_accepts.sh --get_pip_url "$GET_PIP_URL" --playbook_name "$PLAYBOOK_NAME" --playbook_base_url "$PLAYBOOK_BASE_URL" -r "$REGION" --vault_password $VAULT_PASSWORD \ No newline at end of file