Skip to content

Commit

Permalink
[FIX] bugs fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
ismoilovdevml committed Nov 11, 2024
1 parent 6f5c379 commit e0742fb
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 11 deletions.
70 changes: 70 additions & 0 deletions Ansible/hashicorp-vault/configure_vault.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
---
- name: Configure HashiCorp Vault
hosts: all
become: yes
gather_facts: yes
vars_files:
- vars.yml
tasks:
- name: Create Vault configuration directory
ansible.builtin.file:
path: "{{ vault_config_path }}"
state: directory
owner: vault
group: vault
mode: '0755'

- name: Create Vault data directory
ansible.builtin.file:
path: "{{ vault_data_path }}"
state: directory
owner: vault
group: vault
mode: '0755'

- name: Create Vault configuration file
ansible.builtin.template:
src: vault.hcl.j2
dest: "{{ vault_config_path }}/vault.hcl"
owner: vault
group: vault
mode: '0644'
notify: Restart Vault

- name: Enable and start Vault service
ansible.builtin.systemd:
name: vault
enabled: yes
state: started

- name: Check if Vault is already initialized
command: vault status
register: vault_status
failed_when: false
changed_when: false
environment:
VAULT_ADDR: "http://127.0.0.1:8200"

- name: Initialize Vault
command: vault operator init -format=json
register: vault_init
when: "'Initialized' not in vault_status.stdout"
environment:
VAULT_ADDR: "http://127.0.0.1:8200"

- name: Display Unseal Keys and Root Token
debug:
msg: |
Unseal Keys:
{% for key in vault_init.json.unseal_keys_b64 %}
- {{ key }}
{% endfor %}
Root Token: {{ vault_init.json.root_token }}
when: vault_init is defined and 'unseal_keys_b64' in vault_init.json
failed_when: vault_init.json is not defined

handlers:
- name: Restart Vault
ansible.builtin.systemd:
name: vault
state: restarted
15 changes: 4 additions & 11 deletions Ansible/hashicorp-vault/install_package.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
---
- name: Install HashiCorp Vault on multiple operating systems
- name: Install and Configure HashiCorp Vault
hosts: all
become: yes
gather_facts: yes
vars_files:
- vars.yml
tasks:
- name: Add HashiCorp GPG key for Ubuntu/Debian
ansible.builtin.apt_key:
Expand Down Expand Up @@ -88,13 +90,4 @@
ansible.builtin.yum:
name: vault
state: present
when: ansible_facts['os_family'] == "Amazon"

- name: Verify Vault installation and display version
ansible.builtin.shell: "vault --version"
register: vault_version
changed_when: false

- name: Display Vault installation success message
ansible.builtin.debug:
msg: "HashiCorp Vault installation successful! Version: {{ vault_version.stdout }}"
when: ansible_facts['os_family'] == "Amazon"
5 changes: 5 additions & 0 deletions Ansible/hashicorp-vault/vars.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
vault_config_path: /etc/vault.d
vault_data_path: /opt/vault/data
vault_listen_address: "0.0.0.0:8200"
vault_api_addr: "http://127.0.0.1:8200"
10 changes: 10 additions & 0 deletions Ansible/hashicorp-vault/vault.hcl.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
storage "file" {
path = "{{ vault_data_path }}"
}

listener "tcp" {
address = "{{ vault_listen_address }}"
tls_disable = 1
}

api_addr = "{{ vault_api_addr }}"

0 comments on commit e0742fb

Please sign in to comment.