aboutsummaryrefslogtreecommitdiff
path: root/content/blog/ansible/ansible-vault-example.md
diff options
context:
space:
mode:
authorJulien Dessaux2021-03-11 19:47:26 +0100
committerJulien Dessaux2021-03-11 19:47:26 +0100
commit1a4981a826bb94c478c6f49721396ec03e02649c (patch)
treecbd779f6f8e36a28f4d6bd2788c21ce10d9ef122 /content/blog/ansible/ansible-vault-example.md
parentSeveral fixes (diff)
downloadwww-1a4981a826bb94c478c6f49721396ec03e02649c.tar.gz
www-1a4981a826bb94c478c6f49721396ec03e02649c.tar.bz2
www-1a4981a826bb94c478c6f49721396ec03e02649c.zip
First big articles reformatting now that I properly understand hugo
Diffstat (limited to 'content/blog/ansible/ansible-vault-example.md')
-rw-r--r--content/blog/ansible/ansible-vault-example.md30
1 files changed, 19 insertions, 11 deletions
diff --git a/content/blog/ansible/ansible-vault-example.md b/content/blog/ansible/ansible-vault-example.md
index fb6ef45..ac68feb 100644
--- a/content/blog/ansible/ansible-vault-example.md
+++ b/content/blog/ansible/ansible-vault-example.md
@@ -1,17 +1,31 @@
---
title: "Ansible vault example"
-linkTitle: "Ansible vault example"
date: 2018-02-21
-description: >
- Ansible vault example
+description: Getting started with ansible vault
+tags:
+ - ansible
---
+## Editing a protected file
+
Here is how to edit a vault protected file :
{{< highlight sh >}}
ansible-vault edit hostvars/blah.yml
{{< / highlight >}}
-Here is how to put a multiline entry like a private key in vault (for a simple value, just don't use a `|`):
+## Using a vault entry in a task or a jinja template
+
+It is as simple as using any variable :
+{{< highlight yaml >}}
+- copy:
+ path: /etc/ssl/private.key
+ mode: 0400
+ content: '{{ ssl_key }}'
+{{< / highlight >}}
+
+## How to specify multiple lines entries
+
+This is actually a yaml question, not a vault one but since I ask myself this frequently in this context here is how to put a multiple lines entry like a private key in vault (for a simple value, just don't use a `|`):
{{< highlight yaml >}}
ssl_key : |
@@ -21,13 +35,7 @@ ssl_key : |
----- END PRIVATE KEY -----
{{< /highlight >}}
-And here is how to use it in a task :
-{{< highlight yaml >}}
-- copy:
- path: /etc/ssl/private.key
- mode: 0400
- content: '{{ ssl_key }}'
-{{< / highlight >}}
+## How to run playbooks when vault values are needed
To run a playbook, you will need to pass the `--ask-vault` argument or to export a `ANSIBLE_VAULT_PASSWORD_FILE=/home/julien/.vault_pass.txt` variable (the file needs to contain a single line with your vault password here).