Skip to content

Commit

Permalink
Separate vault sidecar (#158)
Browse files Browse the repository at this point in the history
* adding oracle linux to consul role support (#147)

* bumping terraform versions

* bumping github actions version

* linting

* linting

* fixing consul

* stuff

* hotfixes

* hotfixes

* hotfix hs_workspace injection in scaleway delegation playbook

* hotfix hs_workspace injection in scaleway delegation playbook

* hotfix public_domain

* feat(#155): Separate vault-sidecar from consul role

This Ansible role installs and configures the Vault-sidecar proxy to integrate Vault nodes into the Consul Service Mesh.

* feat(#155): Separate vault-sidecar from consul role

Removed  variable

---------

Co-authored-by: Aurélien Maury <aurelienmaury@users.noreply.github.com>
Co-authored-by: Aurélien Maury <amaury@wescale.fr>
Co-authored-by: Jamel ABASSOU <jamel.abassou@wescale.fr>
  • Loading branch information
4 people committed Mar 22, 2024
1 parent 4cf5d2d commit 1fb11df
Show file tree
Hide file tree
Showing 12 changed files with 104 additions and 6 deletions.
7 changes: 7 additions & 0 deletions playbooks/21_consul_install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,10 @@
roles:
- role: "envoy"
- role: "consul"

tasks:
- name: Include vault-sidecar role if required
include_role:
name: vault-sidecar
when: hs_install_vault_sidecar | bool

Check failure on line 16 in playbooks/21_consul_install.yml

View workflow job for this annotation

GitHub Actions / ansible-lint

yaml[new-line-at-end-of-file]

No new line character at the end of file

Check failure on line 16 in playbooks/21_consul_install.yml

View workflow job for this annotation

GitHub Actions / ansible-lint

yaml[trailing-spaces]

Trailing spaces
1 change: 1 addition & 0 deletions playbooks/group_vars/all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ tf_module_dest: "{{ hs_workspace_tf_modules_dir }}/{{ tf_module_name }}"

glxclans_host_service_user_name: "caretaker"

hs_install_vault_sidecar : true

Check failure on line 34 in playbooks/group_vars/all.yml

View workflow job for this annotation

GitHub Actions / ansible-lint

yaml[new-line-at-end-of-file]

No new line character at the end of file

Check failure on line 34 in playbooks/group_vars/all.yml

View workflow job for this annotation

GitHub Actions / ansible-lint

yaml[colons]

Too many spaces before colon
6 changes: 0 additions & 6 deletions roles/consul/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,6 @@
timeout: 60
when: __hs_consul_is_minion

- name: Execute os-specific _consul_masters tasks
include_tasks: "common/_consul_masters.yml"
when: __hs_consul_is_master
tags:
- hs_consul_masters

- name: Execute os-specific _consul_minions tasks
include_tasks: "common/_consul_minions.yml"
when: __hs_consul_is_minion
Expand Down
17 changes: 17 additions & 0 deletions roles/vault-sidecar/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Ansible Role: vault-sidecar

This Ansible role installs and configures the Vault-sidecar proxy to integrate Vault nodes into the Consul Service Mesh.

## Operation

This role automates the installation and configuration of the Vault-sidecar proxy to facilitate the integration of Vault nodes into the Consul Service Mesh. Here are the main operational steps:

1. **Dependency Installation**: The role installs necessary dependencies to run the proxy, such as Consul and Vault.

2. **Proxy Configuration**: Configuration files required for the proxy are generated using Jinja2 templates. These files include Consul service configuration for the proxy, system environment variables, and systemd service.

3. **Service Activation**: Once the configuration is generated, the systemd service for the proxy is activated and started.

## Usage

To utilize this role in your Ansible playbooks, you need to define the variable `hs_install_vault_sidecar` as `true` or `false` in your `playbooks/group_vars/all.yml` file, depending on your requirements. Here's how you can include it in your playbook:
3 changes: 3 additions & 0 deletions roles/vault-sidecar/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
hs_consul_https_address: "0.0.0.0"
hs_consul_api_port: "8501"
7 changes: 7 additions & 0 deletions roles/vault-sidecar/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
# handlers file for vault-sidecar
- name: Reload consul
systemd:
name: consul
state: reloaded
become: yes

Check failure on line 7 in roles/vault-sidecar/handlers/main.yml

View workflow job for this annotation

GitHub Actions / ansible-lint

yaml[truthy]

Truthy value should be one of \[false, true]
20 changes: 20 additions & 0 deletions roles/vault-sidecar/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---

Check failure on line 1 in roles/vault-sidecar/meta/main.yml

View workflow job for this annotation

GitHub Actions / ansible-lint

schema[meta]

$.galaxy_info.role_name 'vault-sidecar' does not match '^\[a-z]\[a-z0-9_]+$'. See https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_reuse_roles.html#using-role-dependencies
galaxy_info:
role_name: "vault-sidecar"
author: "Team"
description: Hashistack Vault Sidecar
issue_tracker_url: https://github.com/wescale/hashistack/issues
min_ansible_version: "2.14"
license: MIT
standalone: false
platforms:
- name: Debian
versions:
- bullseye
galaxy_tags:
- hashicorp
- system
- vault
- sidecar

dependencies: []
47 changes: 47 additions & 0 deletions roles/vault-sidecar/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
- name: Installer le proxy envoy pour Vault si install_envoy_proxy est vrai

Check failure on line 2 in roles/vault-sidecar/tasks/main.yml

View workflow job for this annotation

GitHub Actions / ansible-lint

key-order[task]

You can improve the task key order to: name, when, tags, block
block:
- name: Render vault-sidecar consul service
template:
src: "vault-sidecar.consul.j2"
dest: "/etc/consul.d/vault-sidecar.svc.hcl"
owner: consul
group: consul
mode: 0640
notify: Reload consul

- name: Force running of all notified handlers now
meta: flush_handlers

- name: Wait for consul api
wait_for:
host: "{{ hs_consul_https_address }}"
port: "{{ hs_consul_api_port }}"
timeout: 60

- name: Render vault-sidecar systemd env file
template:
src: "vault-sidecar.env.j2"
dest: "/etc/consul.d/vault-sidecar.env"
owner: consul
group: consul
mode: 0640
notify: Restart vault-sidecar

- name: Render vault-sidecar systemd service
template:
src: "vault-sidecar.service.j2"
dest: "/lib/systemd/system/vault-sidecar.service"
owner: consul
group: consul
mode: 0640
notify: Restart vault-sidecar

- name: Activate vault-sidecar service
systemd:
state: started
enabled: true
name: vault-sidecar
when: hs_install_vault_sidecar and __hs_consul_is_master
tags:
- hs_consul_is_masters
File renamed without changes.
2 changes: 2 additions & 0 deletions roles/vault-sidecar/vars/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
# vars file for vault-sidecar

0 comments on commit 1fb11df

Please sign in to comment.