Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ansible vault #14

Open
wants to merge 87 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
87 commits
Select commit Hold shift + click to select a range
0e96c91
Create main.yml
jfernando0911 Apr 28, 2022
ddaf720
Update main.yml
jfernando0911 Apr 28, 2022
8cf722a
Update main.yml
jfernando0911 Apr 28, 2022
8428fbd
Update main.yml
jfernando0911 Apr 28, 2022
2f9b557
Update main.yml
jfernando0911 Apr 28, 2022
0c00abb
Update main.yml
jfernando0911 Apr 28, 2022
23abe14
Update main.yml
jfernando0911 Apr 28, 2022
fdd5816
Update main.yml
jfernando0911 Apr 28, 2022
eb99a47
Update index.html
jfernando0911 Apr 28, 2022
f3e2edb
Update Dockerfile
jfernando0911 Apr 28, 2022
a67693f
Update index.html
jfernando0911 Apr 29, 2022
4c07b95
Update main.yml
jfernando0911 Apr 29, 2022
8ea1399
Update index.html
jfernando0911 Apr 29, 2022
205b585
Update index.html
jfernando0911 Apr 29, 2022
07df2da
Adding the helm chart
jfernando0911 May 3, 2022
c1e3010
Adding the integrativeprojectchart helm chart to the dockerignore file
jfernando0911 May 3, 2022
cd7084a
Created a new yml workflow for the deployment on Kubernetes
jfernando0911 May 3, 2022
c4d2f72
Merge branch 'master' of https://github.com/jfernando0911/pacman_repo…
jfernando0911 May 3, 2022
e3be200
Removing single quotes from secrets.AZURE_CREDENTIALS
jfernando0911 May 3, 2022
35e89dd
Modifying cluster-name and resource-group from the deploy.yml file
jfernando0911 May 3, 2022
1f4f96c
Modified the login and az cli in the deploy.yml file
jfernando0911 May 3, 2022
7fadb7f
Removed the azure/aks-set-context@v1 section from the deploy file'
jfernando0911 May 3, 2022
3397250
Added a installation of the azure cli and mofified the Azure CLI acti…
jfernando0911 May 3, 2022
cf296d6
Added az account set subscription to the Azure CLI Action step from t…
jfernando0911 May 3, 2022
2b22151
Changed the versions from Azure CLI Action from the deploy.yml file
jfernando0911 May 3, 2022
619ec96
Changed the uses from the Azure CLI Action step
jfernando0911 May 3, 2022
c8e5ed9
Removing the azcliversion from the Azure CLI Action step
jfernando0911 May 3, 2022
f127890
Added the azcliversion to latest to the the Azure CLI Action step
jfernando0911 May 3, 2022
4d9c218
Changing deploy.yml azure credentials
jfernando0911 May 3, 2022
a348405
Modifying the helm command
jfernando0911 May 3, 2022
bd71f22
Modified the working directory and command to install the pacm-man ch…
jfernando0911 May 3, 2022
f7b908a
Changing helm chart source directory
jfernando0911 May 3, 2022
0766acb
Packaging the helm chart
jfernando0911 May 3, 2022
81e5fff
Modified the helm install command to install the chart package
jfernando0911 May 3, 2022
f1699ae
Added the installing kubectl step to the github workflow called deplo…
jfernando0911 May 3, 2022
5b0ffcf
Removed the version from the stel installing kubectl from the deploy.…
jfernando0911 May 3, 2022
875abbf
Added a step 'Get the cluster info' to verify if we can access the cl…
jfernando0911 May 3, 2022
908c93f
Added a command to check the .kube/config file for debugging porpuses
jfernando0911 May 3, 2022
05c2720
Cat the kube config file
jfernando0911 May 3, 2022
4d0c2c9
Adding sudo permissions to 'Read the kube config' step on the pipelin…
jfernando0911 May 3, 2022
dee5191
Adding the step 'Adding the kubernetes context' with new credentials
jfernando0911 May 3, 2022
054f296
Added a name 'Set up k8s secret' and a added a conditional to 'Rollin…
jfernando0911 May 3, 2022
b3d7d22
Updating the index.html file with a modification to the menu of the game
jfernando0911 May 3, 2022
3c44da0
Creation of a worflow to uninstall the helm chart from the kubernetes…
jfernando0911 May 3, 2022
c1f5bd5
Merge branch 'master' of https://github.com/jfernando0911/pacman_repo…
jfernando0911 May 3, 2022
376f278
Created the update_deploy.file to update the image of the pods from t…
jfernando0911 May 4, 2022
17d61ce
Added a new step Addning the kubernetes context, a step to login diff…
jfernando0911 May 4, 2022
793457e
Modified the main.yml file with a shorter versin to login to Azure an…
jfernando0911 May 4, 2022
fd4a6dd
Modified the setup of the context for the deploy.yml file
jfernando0911 May 4, 2022
57829b2
Added a new way to set the the aks context
jfernando0911 May 4, 2022
0faa19f
Added a new name to the set aks context step from the deploy.yml file
jfernando0911 May 4, 2022
eb5e27f
Changed the command helm install for helm upgrade in the deploy.yml file
jfernando0911 May 4, 2022
c664d20
Changing new game section from the game menu
jfernando0911 May 4, 2022
77459cb
Modified the update_deploy.yml file, removed the helm uninstall and a…
jfernando0911 May 4, 2022
39fe783
Merge branch 'master' of https://github.com/jfernando0911/pacman_repo…
jfernando0911 May 4, 2022
4e3441f
Updating the Nuevo juego from the game menu index.html file
jfernando0911 May 4, 2022
590d975
Added vault step to store the api response in a variable
jfernando0911 May 5, 2022
6d015da
Merge branch 'master' of https://github.com/jfernando0911/pacman_repo…
jfernando0911 May 5, 2022
9b54847
Changed the url f the vault step
jfernando0911 May 5, 2022
a0bdbb9
Added the password api response to the vault step
jfernando0911 May 5, 2022
fecf799
Added a new ip for the vault server
jfernando0911 May 5, 2022
406a43b
Added new credentials to the deploy.yml file from vault
jfernando0911 May 5, 2022
8057946
deploy.yml modification
jfernando0911 May 5, 2022
8486f57
Modified the helm chart with a new container azure registry
jfernando0911 May 5, 2022
f48363d
Modified deploy.yml
jfernando0911 May 5, 2022
71a78c0
Modified deploy.yml
jfernando0911 May 5, 2022
33d1bc6
Modified the template/hpa.yaml file changing the averageUtilization f…
jfernando0911 May 6, 2022
0373b16
Added a new version of the chart
jfernando0911 May 6, 2022
4752ef1
New modifications fr the deploy.yml and main.yml
jfernando0911 May 7, 2022
5bb2ed8
Added new values for the vault secrets in the github action workflow
jfernando0911 May 7, 2022
1ed5e67
x
jfernando0911 May 7, 2022
dbcefaf
Removed the namespace from all the templates of the chart integrative…
jfernando0911 May 8, 2022
5ed0073
Deleted the old packed chart
jfernando0911 May 8, 2022
6bb0a71
Created a new packed chart with new settings
jfernando0911 May 8, 2022
54076b4
Changed the structure of the deploy.yml file
jfernando0911 May 8, 2022
ab3cfa7
Changed the namepace to pacman-namespace instead of default for the h…
jfernando0911 May 8, 2022
ccffbac
Added a new to create a secret from kubernetes
jfernando0911 May 8, 2022
e13d5ab
Fixed typo from the deploy.yml dilw
jfernando0911 May 8, 2022
39bddb8
Added the helm installation again for the deploy yml file
jfernando0911 May 8, 2022
9f78845
Added the uninstalling of the chart and removing of the namespace
jfernando0911 May 8, 2022
b76512c
Removed the installing of helm and kubectl tool from the deploy.yml file
jfernando0911 May 8, 2022
197d2b6
Changed names and fixed typos from the deploy.yml file
jfernando0911 May 8, 2022
03ef946
Removed unnecesary double quotes from the main.yml file
jfernando0911 May 8, 2022
b5b5eba
Removed unnecesary steps, installations of helm and kubectl from the …
jfernando0911 May 8, 2022
70cf57c
Removed 'Install Azure cli', 'Install Kubectl CLI, and changed the co…
jfernando0911 May 8, 2022
dbe9c17
Changed the name of the update_deploy.yml file
jfernando0911 May 8, 2022
cab108f
Se agrega ansible y Vault
AmeyalliRosas May 9, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
npm-debug.log
integrativeprojectchart
60 changes: 60 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: 'Deploy'

on:

workflow_dispatch:

jobs:

deployHelmChart:
name: Deploy Helm chart to Kubernetes Cluster
runs-on: ubuntu-latest
environment: Test

defaults:
run:
shell: bash

steps:

- name: Checkout
uses: actions/checkout@v3

- name: Import Secrets
uses: hashicorp/[email protected]
with:
url: ${{ secrets.VAULT_IP }}
token: ${{ secrets.VAULT_TOKEN }}
secrets: |
kv/azure username | AZURE_VAULT_USERNAME;
kv/azure password | AZURE_VAULT_PASSWORD;
kv/azure_container username | AZURE_VAULT_CONTAINER_USERNAME;
kv/azure_container password | AZURE_VAULT_CONTAINER_PASSWORD;

- name: Login to Azure CLI
run: |
az login -u $AZURE_VAULT_USERNAME -p $AZURE_VAULT_PASSWORD

- name: Set aks context
uses: azure/[email protected]
with:
resource-group: Integrative-DevOps-Project
cluster-name: example-aks1

- name: Create a new namespace named pacman-namespace
run: |
kubectl create namespace pacman-namespace

- name: Create docker-registry secret for K8s
run: |
kubectl create secret docker-registry acr-secret \
--namespace pacman-namespace \
--docker-server=containerregistry1123581321.azurecr.io \
--docker-username=$AZURE_VAULT_CONTAINER_USERNAME \
--docker-password=$AZURE_VAULT_CONTAINER_PASSWORD

- name: Installing integrativeprojectchart
working-directory: integrativeprojectchart/charts
run: |
helm install pacman-chart integrativeprojectchart-0.1.0.tgz --namespace pacman-namespace

37 changes: 37 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: 'Push Image ACR'

on:

workflow_dispatch:

jobs:
ContainerRegistry:
runs-on: ubuntu-latest
defaults:
run:
shell: bash

steps:

- name: Checkout
uses: actions/checkout@v3

- name: Import Secrets
uses: hashicorp/[email protected]
with:
url: ${{ secrets.VAULT_IP }}
token: ${{ secrets.VAULT_TOKEN }}
secrets: |
kv/azure username | AZURE_VAULT_USERNAME;
kv/azure password | AZURE_VAULT_PASSWORD;

- name: Login to Azure CLI and Azure Container Registry
run: |
az login -u $AZURE_VAULT_USERNAME -p $AZURE_VAULT_PASSWORD
az acr login --name ${{ secrets.CONTAINER_NAME }}

- name: Build and push docker image to azure registry
working-directory: ./docker
run: |
docker build . -t ${{ secrets.CONTAINER_NAME }}/jesus/pacman-nodejs-app:latest
docker push ${{ secrets.CONTAINER_NAME }}/jesus/pacman-nodejs-app:latest
48 changes: 48 additions & 0 deletions .github/workflows/remove_deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: 'Remove deploy'

on:

workflow_dispatch:

jobs:

uninstallHelm:
name: 'Update image on deployment'
runs-on: ubuntu-latest

defaults:
run:
shell: bash

steps:

- name: Checkout
uses: actions/checkout@v3

- name: Import Secrets
uses: hashicorp/[email protected]
with:
url: ${{ secrets.VAULT_IP }}
token: ${{ secrets.VAULT_TOKEN }}
secrets: |
kv/azure username | AZURE_VAULT_USERNAME;
kv/azure password | AZURE_VAULT_PASSWORD;

- name: "Login to Azure CLI"
run: |
az login -u $AZURE_VAULT_USERNAME -p $AZURE_VAULT_PASSWORD

- name: Set aks context
uses: azure/[email protected]
with:
resource-group: Integrative-DevOps-Project
cluster-name: example-aks1


- name: 'Uninstalling helm chart'
run: |
helm uninstall pacman-chart --namespace pacman-namespace

- name: 'Delete pacman-namespace'
run: |
kubectl delete namespace pacman-namespace
45 changes: 45 additions & 0 deletions .github/workflows/update_deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: 'Update deployment'

on:

workflow_dispatch:

jobs:

restartDeployment:
name: 'Update the the image from the replicas'
runs-on: ubuntu-latest

defaults:
run:
shell: bash

steps:

- name: Checkout
uses: actions/checkout@v3


- name: Import Secrets
uses: hashicorp/[email protected]
with:
url: ${{ secrets.VAULT_IP }}
token: ${{ secrets.VAULT_TOKEN }}
secrets: |
kv/azure username | AZURE_VAULT_USERNAME;
kv/azure password | AZURE_VAULT_PASSWORD;

- name: "Login to Azure CLI"
run: |
az login -u $AZURE_VAULT_USERNAME -p $AZURE_VAULT_PASSWORD


- name: Set aks context
uses: azure/[email protected]
with:
resource-group: Integrative-DevOps-Project
cluster-name: example-aks1

- name: Rolling restart deployment deployment.apps/pacman
run: |
kubectl rollout restart deployment.apps/pacman -n pacman-namespace
Binary file added ansible-vault/.DS_Store
Binary file not shown.
5 changes: 5 additions & 0 deletions ansible-vault/inventory.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#13.67.215.79 ansible_user=azureuser
#proyectvm.centralus.cloudapp.azure.com ansible_user=azureuser
#40.77.26.179 ansible_user=azureuser
#secretsvm.centralus.cloudapp.azure.com ansible_user=azureuser
13.89.245.9 ansible_user=azureuser
17 changes: 17 additions & 0 deletions ansible-vault/playbook.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
- hosts: all
become: true
remote_user: azureuser
become_user: root
become_method: sudo
roles:
- vault

- hosts: all
vars:
unseal_keys_dir_output: "{{ playbook_dir }}/unsealKey/"
root_token_dir_output: "{{ playbook_dir }}/rootKey/"
roles:
- vault-init
- vault-unseal

29 changes: 29 additions & 0 deletions ansible-vault/roles/vault-init/.travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
language: python
python: "2.7"

# Use the new container infrastructure
sudo: false

# Install ansible
addons:
apt:
packages:
- python-pip

install:
# Install ansible
- pip install ansible

# Check ansible version
- ansible --version

# Create ansible.cfg with correct roles_path
- printf '[defaults]\nroles_path=../' >ansible.cfg

script:
# Basic role syntax check
- ansible-playbook tests/test.yml -i tests/inventory --syntax-check

notifications:
webhooks: https://galaxy.ansible.com/api/v1/notifications/
38 changes: 38 additions & 0 deletions ansible-vault/roles/vault-init/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
Role Name
=========

A brief description of the role goes here.

Requirements
------------

Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required.

Role Variables
--------------

A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well.

Dependencies
------------

A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles.

Example Playbook
----------------

Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too:

- hosts: servers
roles:
- { role: username.rolename, x: 42 }

License
-------

BSD

Author Information
------------------

An optional section for the role authors to include contact information, or a website (HTML is not allowed).
6 changes: 6 additions & 0 deletions ansible-vault/roles/vault-init/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
# defaults file for roles/vault-init
unseal_keys_dir_output: "{{ playbook_dir }}/unsealKey/"
root_token_dir_output: "{{ playbook_dir }}/rootKey/"
vault_addr: 'http://0.0.0.0:8200'
#vault_addr: 'http://127.0.0.1:8200'
37 changes: 37 additions & 0 deletions ansible-vault/roles/vault-init/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
# tasks file for roles/vault-init
- name: Create unseal directories
file:
path: "{{ unseal_keys_dir_output }}"
state: "directory"
delegate_to: localhost

- name: Create root key directories
file:
path: "{{ root_token_dir_output }}"
state: "directory"
delegate_to: localhost

- name: Initialise Vault operator
shell: vault operator init -key-shares=5 -key-threshold=3 -format json
environment:
VAULT_ADDR: '{{ vault_addr }}'
register: vault_init_results


- name: Parse output of vault init
set_fact:
vault_init_parsed: "{{ vault_init_results.stdout | from_json }}"

- name: Write unseal keys to files
copy:
dest: "{{ unseal_keys_dir_output }}/unseal_key_{{ item.0 }}"
content: "{{ item.1 }}"
with_indexed_items: "{{ vault_init_parsed.unseal_keys_hex }}"
delegate_to: localhost

- name: Write root token to file
copy:
content: "{{ vault_init_parsed.root_token }}"
dest: "{{root_token_dir_output}}/rootkey"
delegate_to: localhost
2 changes: 2 additions & 0 deletions ansible-vault/roles/vault-init/tests/inventory
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
localhost

5 changes: 5 additions & 0 deletions ansible-vault/roles/vault-init/tests/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
- hosts: localhost
remote_user: root
roles:
- roles/vault-init
2 changes: 2 additions & 0 deletions ansible-vault/roles/vault-init/vars/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
# vars file for roles/vault-init
29 changes: 29 additions & 0 deletions ansible-vault/roles/vault-unseal/.travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
language: python
python: "2.7"

# Use the new container infrastructure
sudo: false

# Install ansible
addons:
apt:
packages:
- python-pip

install:
# Install ansible
- pip install ansible

# Check ansible version
- ansible --version

# Create ansible.cfg with correct roles_path
- printf '[defaults]\nroles_path=../' >ansible.cfg

script:
# Basic role syntax check
- ansible-playbook tests/test.yml -i tests/inventory --syntax-check

notifications:
webhooks: https://galaxy.ansible.com/api/v1/notifications/
Loading