{"id":19648889,"url":"https://github.com/laardee/__outdated_serverless-deployment-ansible","last_synced_at":"2026-05-11T02:01:46.615Z","repository":{"id":150520336,"uuid":"81027890","full_name":"laardee/__outdated_serverless-deployment-ansible","owner":"laardee","description":"An example Ansible playbook for deploying Serverless service.","archived":false,"fork":false,"pushed_at":"2017-02-10T10:22:43.000Z","size":26,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-09T23:11:53.289Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/laardee.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-02-05T22:46:58.000Z","updated_at":"2017-02-10T10:21:34.000Z","dependencies_parsed_at":"2023-04-25T22:47:39.508Z","dependency_job_id":null,"html_url":"https://github.com/laardee/__outdated_serverless-deployment-ansible","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/laardee%2F__outdated_serverless-deployment-ansible","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/laardee%2F__outdated_serverless-deployment-ansible/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/laardee%2F__outdated_serverless-deployment-ansible/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/laardee%2F__outdated_serverless-deployment-ansible/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/laardee","download_url":"https://codeload.github.com/laardee/__outdated_serverless-deployment-ansible/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240958851,"owners_count":19884908,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-11T14:50:38.698Z","updated_at":"2026-05-11T02:01:41.574Z","avatar_url":"https://github.com/laardee.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"OUTDATED -\u003e Moved to https://github.com/sc5/serverless-deployment-ansible\n\n\n\n\n\n# Ansible Playbook for Serverless Framework\n\nExample [Ansible](https://github.com/ansible/ansible) playbook for deploying [Serverless](https://github.com/serverless/serverless) service.\n\nBenefits on using this approach:\n\n* The service can be tested in the build flow\n* Stack deployment is faster when the service is already compiled and test are runned\n* Same tested package is used in all the stages\n\nFor small scale serverless projects there is also a lite version that builds and deploys Serverless service [serverless-deployment-ansible-lite](https://github.com/SC5/serverless-deployment-ansible-lite).\n\n**Contents**\n\n[Project Structure](#project-structure)\n\n[Setup Local Environment](#setup-local-environment)\n\n[Setup Jenkins](#setup-jenkins)\n\n[Deployment Flow](#deployment-flow)\n\n[Build](#build)\n\n[Deployment](#deployment)\n\n\n## Project Structure\n\n* `group_vars` default variables\n* `inventories` inventory files and variables for environments (development, production, etc.)\n* `roles`\n  * `infra` role for infrastructure, vpc, database etc.\n  * `service` role for Serverless service\n* `scripts` scripts that helps deployment\n\n## Setup Local Environment\n\nIf you are deploying from your local environment, [Docker](https://docs.docker.com/engine/installation/) is required for deploying the playbook or alternatively Ansible and all the dependencies defined in Dockerfile installed in you environment.\n\n## Setup Jenkins\n\nWhen using jenkins for deployment, easiest way is to setup Jenkins into EC2 instance running in your AWS account. Here is quick and dirty instructions how to do that [Jenkins setup instructions](https://github.com/laardee/jenkins-installation)\n\nIn addition to suggested plugins, install following plugins also:\n\n* Pipeline: AWS Steps\n* Version Number Plug-In\n\n## Deployment flow\n\n1. Create artifact from the Serverless service that contains parameterized CloudFormation Jinja2 template and functions package\n2. Upload artifact to S3 (or Artifactory or other file system).\n3. Download artifact with Ansible\n4. Extract and create environment specific CloudFormation templates\n5. Deploy stack to AWS\n\n## Build\n\nCreate S3 bucket for artifacts using AWS Console or aws-cli.\n\n```Bash\naws s3api create-bucket --bucket my-artifacts-bucket --region us-east-1\n```\n\n### Local environment\n\n[serverless-deployment-example-service](https://github.com/SC5/serverless-deployment-example-service) has ready made setup for [serverless-ansible-build-plugin](https://github.com/laardee/serverless-ansible-build-plugin) that helps the artifact creation process.\n\nIn the serverless-deployment-example-service, scripts directory there is `create-artifact.sh` that builds service and creates artifact with recommended filename. \n\nExecuting `create-artifact.sh` with param `-p` creates tar package, `-s` parameter is mandatory and needs to match service name.\n\nFollowing snippet will create package named e.g. `example-service-1.20170206.1-799dcd4.tar.gz`. Where\n\n* `example-service` is service name (set with `-s`)\n* `1` is version for service (set with `-v`, optional, defaults to 1)\n* `20170206` is build date\n* `1` is number of the build in build date (set with `-b`, optional, defaults to 1)\n* `799dcd4` is short hash from git\n\n```Bash\n./scripts/create-artifact.sh -p -s example-service\n```\n\nThe `1.20170206.1-799dcd4` part is the `service_version` what is used later in Ansible vars.\n\nThen copy the artifact to you artifact S3 bucket.\n\n### Jenkins\n\nFollowing pipeline script will\n\n1. checkouts the service from repository\n2. creates version tag\n3. builds service\n4. uploads artifact to S3 bucket\n\n```Groovy\nMAJOR_VERSION = \"1\"\nARTIFACTS_BUCKET = \"serverless-ansible-artifacts\"\nSERVICE = \"example-service\"\nnode {\n    stage('Checkout service repo') {\n        dir('project') {\n            git 'https://github.com/SC5/serverless-deployment-example-service.git'\n        }\n    }\n    \n    stage('Set version') {\n        dir('project') {\n            gitCommitShort = sh(returnStdout: true, script: 'git rev-parse --short HEAD').trim()\n            version = VersionNumber(projectStartDate: '2016-10-01', skipFailedBuilds: true, versionNumberString: '${BUILD_DATE_FORMATTED, \"yyyyMMdd\"}.${BUILDS_TODAY, X}-${gitCommitShort}', versionPrefix: \"${MAJOR_VERSION}.\")\n            currentVersion = \"${version}\" + \"${gitCommitShort}\"\n            \n        }\n    }\n    \n    stage('Build') {\n        dir('project') {\n            withEnv([\"VERSION=${currentVersion}\"]) {\n                sh \"./scripts/create-artifact.sh -s ${SERVICE}\"\n            }\n        }\n    }\n    \n    stage(\"Copy Artifact to S3\") {\n        dir('artifacts') {\n            withEnv([\"VERSION=${currentVersion}\"]) {\n                sh \"tar -zcf ${SERVICE}-${VERSION}.tar.gz -C ../project/.ansible ${SERVICE}.zip ${SERVICE}.json.j2\"\n                withAWS {\n                   s3Upload(file:\"${SERVICE}-${VERSION}.tar.gz\", bucket:\"${ARTIFACTS_BUCKET}\", path:\"${SERVICE}/${SERVICE}-${VERSION}.tar.gz\")\n                }\n            }\n        }\n    }\n}\n```\n\n## Deployment\n\n1. Define which service version is the one that is to be deployed, take the e.g. `1.20170206.1-799dcd4` part from artifact name created in build step and add it to `service_version: ` in `inventories/development/groups_vars/aws/vars.yml`. When you are ready to deploy service to production, modify the `vars.yml` in `inventories/production/groups_vars/aws/`.\n2. Define artifacts S3 bucket to `artifacts_bucket` variable in `group_vars/aws/vars.yml`, so that ansible knows where to download artifacts. \n\n\n### Local environment\n\nFirst define the service name to `roles/service/tasks/main.yml`\n\n```Yaml\n- set_fact:\n    service_name: example-service\n```\n\nWhen deploying from local environment AWS secrets needs to be passed to deployment container, for that e.g. `.deploy.sh` script in the project root with contents of\n\n```Bash\n#!/usr/bin/env bash\n\nexport AWS_ACCESS_KEY=my-access-key\nexport AWS_SECRET_KEY=my-secret-key\n\n./scripts/deploy-local.sh\n\n```\n\nmight ease up the deployment flow.\n\n1. Build Dockerfile with `./scripts/build-docker.sh`\n2. Run `./.deploy.sh`\n\n### Jenkins\n\nWhen using Jenkins on AWS EC2, the role of the instance needs to have permissions to deploy CloudFormation stacks, create S3 buckets, IAM Roles, Lambda and other services that are used in Serverless service.\n\nFollowing pipeline script will\n\n1. checkout this repository\n2. build docker image for deployment\n3. deploy stacks to AWS\n\n```Groovy\nnode {\n    stage('Checkout repository') {\n        git 'https://github.com/laardee/serverless-deployment-ansible.git'\n    }\n    stage('Build Docker image') {\n       sh \"./scripts/build-docker.sh\"\n    }\n    stage('Deploy') {\n        sh './scripts/deploy-development.sh'\n    }\n}\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flaardee%2F__outdated_serverless-deployment-ansible","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flaardee%2F__outdated_serverless-deployment-ansible","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flaardee%2F__outdated_serverless-deployment-ansible/lists"}