vault_snapshot

Ansible role vault_snapshot

Configure vault_snapshot on Vault.

GitHub GitLab Downloads Version
github gitlab downloads Version

Example Playbook

This example is taken from molecule/default/converge.yml and is tested on each push, pull request and release.

---
- name: Converge
  hosts: all
  become: true
  gather_facts: true

  pre_tasks:
    - name: Read token from remote machine
      ansible.builtin.slurp:
        src: /root/.vault-token
      register: token_raw

  roles:
    - role: robertdebock.vault_snapshot
      vault_snapshot_token: "{{ token_raw['content'] | b64decode }}"
      vault_snapshot_ssl_verify: false
      vault_snapshot_schedules:
        - name: hourly
          interval_seconds: 3600
          retain: 24
          path_prefix: /opt/vault/snapshots/
          storage_type: local
          local_max_space: 1073741824
        - name: hourly-aws
          interval_seconds: 3600
          retain: 24
          path_prefix: /hourly
          storage_type: aws-s3
          aws_s3_bucket: my-bucket
          aws_s3_region: eu-central-1
          aws_access_key_id: some_key
          aws_secret_access_key: some_secret
          aws_s3_enable_kms: false
        - name: hourly-azure
          interval_seconds: 3600
          retain: 24
          path_prefix: /hourly/
          storage_type: azure-blob
          azure_container_name: my-blob
          azure_account_name: some_account
          azure_account_key: some_key

The machine needs to be prepared. In CI this is done using molecule/default/prepare.yml:

---
- name: Prepare
  hosts: all
  become: true
  gather_facts: false

  roles:
    - role: robertdebock.bootstrap
    - role: robertdebock.core_dependencies
    - role: robertdebock.hashicorp
    - role: robertdebock.vault
      vault_type: ent
      vault_hardening_disable_swap: false
    - role: robertdebock.vault_configuration
      vault_configuration_license: "{{ lookup('ansible.builtin.env', 'VAULT_LICENSE') }}"
      vault_configuration_listener_tcp:
        address: "127.0.0.1:8200"
        cluster_address: "127.0.0.1:8201"
        tls_disable: true
      vault_configuration_storage_raft:
        path: "/opt/vault/data"
        node_id: "{{ ansible_hostname }}"

  tasks:
    - name: Flush handlers
      ansible.builtin.meta: flush_handlers

    - name: Start Vault
      ansible.builtin.service:
        name: vault
        state: started

    - name: Initialize Vault
      ansible.builtin.command:
        cmd: vault operator init -format=yaml
      register: vault_init_raw
      environment:
        VAULT_ADDR: "https://localhost:8200"
        VAULT_SKIP_VERIFY: "true"
      changed_when: true

    - name: Store vault_init_raw output as YAML
      ansible.builtin.set_fact:
        vault_init: "{{ vault_init_raw.stdout | from_yaml }}"

    - name: Store root_token
      ansible.builtin.copy:
        content: "{{ vault_init.root_token }}"
        dest: /root/.vault-token
        owner: root
        group: root
        mode: "0640"

    - name: Unseal Vault
      ansible.builtin.command:
        cmd: vault operator unseal {{ item }}
      loop: "{{ vault_init.unseal_keys_b64 }}"
      environment:
        VAULT_ADDR: "https://localhost:8200"
        VAULT_SKIP_VERIFY: "true"
      changed_when: true

Also see a full explanation and example on how to use these roles.

Role Variables

The default values for the variables are set in defaults/main.yml:

---
# defaults file for vault_snapshot

# Set the vault instance address. Similar to `VAULT_ADDR`.
vault_snapshot_address: "https://localhost:8200"

# Set a token to connect to Vault. Similar to `VAULT_TOKEN`.
vault_snapshot_token: ""

# A list of snapshots to configure. Please have look in `molecule/default/converge.yml` for a complete example.
vault_snapshot_schedules: []

# Should SSL certificate verification be disabled?
vault_snapshot_ssl_verify: true

Requirements

State of used roles

The following roles are used to prepare a system. You can prepare your system in another way.

Requirement GitHub GitLab
robertdebock.bootstrap Build Status GitHub Build Status GitLab
robertdebock.core_dependencies Build Status GitHub Build Status GitLab
robertdebock.hashicorp Build Status GitHub Build Status GitLab
robertdebock.vault Build Status GitHub Build Status GitLab
robertdebock.vault_configuration Build Status GitHub Build Status GitLab

Context

This role is a part of many compatible roles. Have a look at the documentation of these roles for further information.

Here is an overview of related roles: dependencies

Compatibility

This role has been tested on these container images:

container tags
Amazon Candidate
Debian all
EL 9
Fedora 39
Ubuntu all

The minimum version of Ansible required is 2.12, tests have been done to:

  • The previous version.
  • The current version.
  • The development version.

If you find issues, please register them in GitHub.

License

Apache-2.0.

Author Information

robertdebock

Please consider sponsoring me.

About

Configure vault_snapshot on Vault.

Install
ansible-galaxy install robertdebock/ansible-role-vault_snapshot
GitHub repository
License
apache-2.0
Downloads
67
Owner
I know my way around (Linux) infrastructure, have a passion for automation, Docker, Ansible, Molecule and ci/cd.