Logo

dev-resources.site

for different kinds of informations.

Ansible Vault Quick Start

Published at
12/28/2020
Categories
ansible
encrypt
devops
cloudopz
Author
vumdao
Categories
4 categories in total
ansible
open
encrypt
open
devops
open
cloudopz
open
Author
6 person written this
vumdao
open
Ansible Vault Quick Start
  • Ansible Vault encrypts variables and files so you can protect sensitive content such as passwords or keys rather than leaving it visible as plaintext in playbooks or roles.

  • 5 steps or less to quick start with ansible vault

1. Create password stored file to hold the master key

passwd_file

~: cat passwd_file
pLECtontABre
Enter fullscreen mode Exit fullscreen mode

2. Generate encrypted password and data conent

  • Password for ssh-login
 $ ansible-vault encrypt_string --vault-id vagrant@passwd_file 'rootroot' --name vagrant
vagrant: !vault |
          $ANSIBLE_VAULT;1.2;AES256;vagrant
          33383365353665376338326665343364373334633265633438366263336638393937366661333430
          6662656233333563333461333962376539353634643563630a386335666632656435363863366339
          39623635363930373264636234653632616536343064313134623535653833353737313236313064
          6335323136366438640a373131373764393337303734386631303133336234343638623233356430
          3135
Encryption successful
Enter fullscreen mode Exit fullscreen mode
  • Data encrypt
⚡ $ ansible-vault encrypt_string --vault-id dev@passwd_file 'my_credential_data' --name 'my_data_encrypted' 
my_data_encrypted: !vault |
          $ANSIBLE_VAULT;1.2;AES256;dev
          65653537303030393632656639333262346565383266643734353865356163363538613736316465
          3734303334396561626538386466356461643035373166360a383735343735663234653736626565
          63363436626135373366633034353762623366333664633964666463373765396335373737313035
          3062393261613966360a373533326637323832633330303230383036636435383165376230656133
          31366231326330336137633035623763396533313735636531623438386632376536
Encryption successful
Enter fullscreen mode Exit fullscreen mode
  • Update the encrypted things to var.yaml
vagrant: !vault |
          $ANSIBLE_VAULT;1.2;AES256;vagrant
          33383365353665376338326665343364373334633265633438366263336638393937366661333430
          6662656233333563333461333962376539353634643563630a386335666632656435363863366339
          39623635363930373264636234653632616536343064313134623535653833353737313236313064
          6335323136366438640a373131373764393337303734386631303133336234343638623233356430
          3135

my_data_encrypted: !vault |
          $ANSIBLE_VAULT;1.2;AES256;dev
          65653537303030393632656639333262346565383266643734353865356163363538613736316465
          3734303334396561626538386466356461643035373166360a383735343735663234653736626565
          63363436626135373366633034353762623366333664633964666463373765396335373737313035
          3062393261613966360a373533326637323832633330303230383036636435383165376230656133
          31366231326330336137633035623763396533313735636531623438386632376536
Enter fullscreen mode Exit fullscreen mode

3. Create ansible task to test decryption

  • test.yml: Variable my_data_encrypted as encrypted value
⚡ $ cat test.yml 
---
- hosts: all
  become: true
  vars_files:
    - var.yaml
  tasks:
    - name: ansible vault test
      debug:
        msg: "{{ my_data_encrypted }}"
Enter fullscreen mode Exit fullscreen mode
  • inventory: variable vagrant as the encrypted value
⚡ $ cat inventory 
[ubuntu]
192.168.121.21

[all:vars]
ansible_connection=ssh
ansible_user=vagrant
ansible_ssh_pass={{ vagrant }}
Enter fullscreen mode Exit fullscreen mode

4. Run ansible-playbook

⚡ $ ansible-playbook test.yml --vault-id dev@passwd_file -i inventory -e @var.yaml
ok: [192.168.121.107]
 ___________________________
< TASK [ansible vault test] >
 ---------------------------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||

ok: [192.168.121.107] => {
    "msg": "my_credential_data"
}
 ____________
< PLAY RECAP >
 ------------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||

192.168.121.107            : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   
Enter fullscreen mode Exit fullscreen mode

Mirror:

Read More

encrypt Article's
25 articles in total
Favicon
Encrypt/Decrypt Data between Python 3 and JavaScript (AES algorithm)
Favicon
HideIPVPN: Unblock, Encrypt, & Explore Freely
Favicon
Encrypt Password Laravel
Favicon
Introduction to the Principles of JavaScript Encryption and JavaScript Obfuscation
Favicon
What is the secure way to store environment variables?
Favicon
Java 01 - Jasypt: Protegendo dados sensíveis com criptografia.
Favicon
How to encrypt a text using Python (key and text) and decrypt that cipher in JavaScript using the same key.
Favicon
Differences Between HTTP and HTTPS?
Favicon
Managing and sharing secrets in a Git repository with Keybase
Favicon
How To Encrypt And Decrypt String In Laravel 9
Favicon
PGP - Create a Public/Private Key Pair(Part 2)
Favicon
PGP - Introduction Encryption and Decryption (Part 1)
Favicon
🔐How to encrypt variables in NodeJS
Favicon
Java - How to Encrypt or Decrypt PDF Documents
Favicon
backup the .env files to git/gist/dropbox in old school way!
Favicon
Protect Python Source Code
Favicon
Python Encrypt Source Code Online
Favicon
Top 15 Modules 2022: Encrypt and Decrypt String Python
Favicon
Email Encryption: What it is, How Does It Work, and How to Encrypt an Email
Favicon
Add Https to Azure Web App with Let's Encrypt
Favicon
Ansible Vault Quick Start
Favicon
Nginx configures free SSL certificate in Windows environment (Let’s Encrypt)
Favicon
Encrypt/ Decrypt PDF Files in Java Application
Favicon
How to use GnuPG for encrypting files on MacOS
Favicon
Protect presentation slides in Java

Featured ones: