CI_CD_Ansible

This playbook will create and provision all web servers within the network with the weight tracker app: https://developer.okta.com/blog/2020/06/01/node-postgres-weight-tracker. This repo you will find:

  • Weight Tracker app deployed with ansible, using roles, variables and different modules.
  • YAML to write ansible configurations.
  • A controller machine which deploy the app to different enviroments (staging and production) using a single playbook.

steps:

  • Install ansible on ubuntu 18.04 with the commands in this site: Installation Guide
  • Create ssh key and copy to remote machine by this command: ssh-keygen
  • Configure remote machine to enable ansible to run it.
  • Edit the hosts file: /etc/hosts and /etc/ansible/hosts - In the hosts file you can define your working groups, such as "staging" or "prodn" and assign to each group their unique properties. Here we will just store there the IPs of the relevant machines. create your groups like this: image image
  • Run a test to verify a connection exists with managed hosts
  • Copy the key to the agents by using ssh-copy-id user@hostname command.
  • Verify connection
  • Make a new directory called enviroment
  • In enviroment directory make 2 directory called - staging and prod
  • In staging and prod make a new directory called "group_vars"
  • In each "group_vars" directory create a YML file there with the same name as your group name( enviroment name) that store the .env variables. for example - PGHOST,OKTA, POSTGRESQL, and IP ADDRESS HOST.
  • In enviroment directory create a new playbook - mkdir playbook -> nano playbook.yml
  • Run playbook : ansible-Playbook Your Play book YAML file --extra-vars "group=your group name var_file_path=enviroment//group_vars/variable file name"

For example: ansible-playbook playbook.yml --extra-vars "group=staging var_file_path=/home/Inbalevi0707/environments/staging/group_vars/staging.yml"

  • You can add few flags for debugging:
    This command will show debugging output ansible-playbook -i hosts -u -vvv This command will ask you to confirm each step ansible-playbook -i hosts -u --step This command will start the playbook on the requested task name ansible-playbook -i hosts -u --start-at-task:""

Node.js Weight Tracker

Demo

This sample application demonstrates the following technologies.

  • hapi - a wonderful Node.js application framework
  • PostgreSQL - a popular relational database
  • Postgres - a new PostgreSQL client for Node.js
  • Vue.js - a popular front-end library
  • Bulma - a great CSS framework based on Flexbox
  • EJS - a great template library for server-side HTML templates

Requirements:

Install and Configuration

  1. Clone or download source files
  2. Run npm install to install dependencies
  3. If you don't already have PostgreSQL, set up using Docker
  4. Create a free Okta developer account and add a web application for this app
  5. Copy .env.sample to .env and change the OKTA_* values to your application
  6. Initialize the PostgreSQL database by running npm run initdb
  7. Run npm run dev to start Node.js

The associated blog post goes into more detail on how to set up PostgreSQL with Docker and how to configure your Okta account.